New update is available. Click here to update.

Last Updated: 2 Dec, 2020

Difficulty: Easy

```
Consider ARR = [[1 , 2 , 3] , [3 , 4 , 1] , [2 , 1 , 2]] and Queries = [[0 , 0 , 1 , 2]], the submatrix with the left top index (0 , 0) and right bottom index (1 , 2) is
[[1 , 2 , 3] ,
[3 , 4 , 1]].
The sum of the submatrix is 14. Hence, the answer is 14 in this case.
```

```
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains three space-separated integers, 'N', M’, and ‘K’, denoting the number of rows and the number of columns in the array 'ARR', and the number of rows in the array 'Queries' respectively.
The Next 'N' lines of each test case contain 'M' space-separated integers denoting the elements of the array 'ARR'.
The Next 'K' lines of each test case contain four space-separated integers denoting the elements of the array ‘Queries’.
```

```
For each test case, print ‘K’ space-separated integers - the sum of the submatrix for each query.
Print the output of each test case in a separate line.
```

```
1 <= N <= 10 ^ 3
1 <= M <= 10 ^ 3
1 <= K <= 10 ^ 3
1 <= ARR[i][j] <= 10 ^ 6
0 <= Queries[i][0] , Queries[i][2] < N
0 <= Queries[i][1] , Queries[i][3] < M
Where 'T' denotes the number of test cases, 'N' and 'M' denotes the number of rows and the number of columns in the array ‘ARR’ respectively, ’K’ denotes the number of rows in the array ‘Queries’, 'ARR[i][j]' denotes the ’j-th’ element of 'i-th' row of the array 'ARR' and 'Queries[i]' contains four integers denoting the left top and right bottom indices of the submatrix.
Time Limit: 1sec
```

SIMILAR PROBLEMS

SudoKube

Posted: 18 May, 2022

Difficulty: Ninja

SudoKube

Posted: 18 May, 2022

Difficulty: Ninja

SudoKube

Posted: 18 May, 2022

Difficulty: Ninja

King Placement

Posted: 22 May, 2022

Difficulty: Moderate

Ninja and the experiment

Posted: 5 Sep, 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: