RECTANGLE SUM

Given a matrix of integers A of size N x M.

Calculate the sum of all submatrices and return the maximum among all those sums.

Note: Rows are numbered from top to bottom and columns are numbered from left to right.

Note: Empty submatrix also need to be considered.



Input Format

The first argument given is the integer matrix A.

Output Format

Calculate the sum of all submatrices and return the maximum among all those sums.  

Constraints

1 <= N, M <= 100
-10000 <= A[i] <= 10000

For Example

Input 1:
    A = [   [1, 3, -2]
            [1, 4, 6]
            [-4, -2, 1]   ]
    
Output 1:
    13
Explaination 1:
 submatrix giving maximum sum is = [ [1, 3, -2] 
                                     [1, 4, 6] ]
                                     

Input 2:
    A = [   [-1, -1]
            [-1, -1]    ]
Output 2:
    0
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving RECTANGLE SUM on Interview Code Editor
Sign Up
to access hints and editorial solutions for RECTANGLE SUM

Discussion


Loading...
Click here to start solving coding interview questions