New update is available. Click here to update.

Posted: 19 Mar, 2021

Difficulty: Moderate

```
'GRID' = [ [1, 2, 3],
[4, 5, 6],
[7, 8, 9] ]
'Q' = 1, left corner = (1, 1), right corner = (2, 2)
submatrix = [ [5, 6],
[8, 9] ]
Answer = 28
```

```
The first line of input contains an integer 'T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains three space-separated integers ‘N’, ‘M’, ‘Q’ number of rows and number of columns in 'GRID' and number of queries.
Then ‘N’ lines follow. Each of the lines contains ‘M’ space-separated integers denoting the elements of the matrix 'GRID'.
Then ‘Q’ lines follow. Each of the lines contains four space-separated integers ‘X1’, ‘Y1’, ‘X2’, ‘Y2’ where (‘X1’, ‘Y1’) is an upper left corner. (‘X2’, ‘Y2’) is the lower right corner.
```

```
For each test case, return the array that contains sum of elements in the submatrix defined by the upper left and lower right corner for each query.
```

```
You don’t need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 5
1 <= N, M <= 10^3
-10^4 <= GRID[i][j] <= 10^4
Time Limit: 1 sec
```

SIMILAR PROBLEMS

NINJA AND HAPPINESS

Posted: 9 Sep, 2022

Difficulty: Hard

DECODE STRING

Posted: 11 Sep, 2022

Difficulty: Moderate

Randomly Sorted

Posted: 13 Nov, 2022

Difficulty: Moderate

Search In A Sorted 2D Matrix

Posted: 23 Nov, 2022

Difficulty: Moderate

Spiral Matrix

Posted: 24 Nov, 2022

Difficulty: Easy

Popular Interview Problems: