Maximum Sum Rectangle Problem Statement
Given a matrix ARR
with dimensions N
x M
, your task is to identify the rectangle within the matrix that has the maximum sum of its elements.
Input:
The first line contains an integer T
denoting the number of test cases. For each test case:
The first line contains two space-separated integers N
and M
(the dimensions of the matrix).
The next N
lines contain M
space-separated integers representing the matrix ARR
.
Output:
For each test case, output the maximum sum of the rectangles possible in the matrix on a new line.
Example:
Explanation:
The input matrix might be:
4 - 5 3 0
-3 2 1 0
1 -3 3 9
The maximum sum rectangle can be from (1,1) to (3,3), yielding a maximum sum of 29.
Constraints:
1 ≤ T ≤ 10
1 ≤ M, N ≤ 75
-10^5 ≤ ARR[i][j] ≤ 10^5
- Time Limit: 1 sec
Note:
No need for any printing, focus on implementing the required function.

AnswerBot
4mo
Find the rectangle within a matrix that has the maximum sum of its elements.
Iterate through all possible rectangles within the matrix
Calculate the sum of each rectangle
Keep track of the maximum sum fo...read more
Help your peers!
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

