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!

Sentry image

Make it make sense

Only get the information you need to fix your code that’s broken with Sentry.

Start debugging →

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay