DEV Community

Debesh P.
Debesh P.

Posted on

1 1 1 1 1

Summed Matrix | GeeksforGeeks‬ Beginner's DSA Sheet | Matrix Problems | With Source Code

hola coders!

In this video, I’ll teach you how to solve the Summed Matrix problem from GeeksforGeeks step by step. If you’ve ever struggled with matrix-based problems, this tutorial is for you!


Problem Link: https://www.geeksforgeeks.org/problems/summed-matrix5834/1

Source Code: https://github.com/debeshp6/Gfg-Tutorials/blob/main/SummedMatrix.java


Code

class Solution {
    static long sumMatrix(long n, long q) {
        // code here

        if(q < 2 || q > n * 2) {
            return 0;
        }

        if(q <= n + 1) {
            return q - 1;
        }

        else {
            return n - (q - n -1);
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Matrix problems are common in coding interviews, competitive programming, and even real-world applications. Learning this concept will boost your problem-solving skills and help you tackle similar problems easily!

Got any doubts? Drop your questions in the comments, and I'll help you out.

happy coding!

Neon image

Serverless Postgres in 300ms (!)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free →

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay