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
8d
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...
Top Go-Jek Android Engineer interview questions & answers
Popular interview questions of Android Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app