
Asked in Yodlee
Maximum Sum Rectangle Problem
Given an M x N matrix of integers ARR
, your task is to identify the rectangle within the matrix that has the greatest sum of its elements.
Input:
The first line of input contains an integer 'T' representing the number of test cases. For each test case, the first line contains two space-separated integers, M and N, indicating the dimensions of the matrix ARR. The following M lines each contain N space-separated integers, representing the elements of the matrix ARR.
Output:
For each test case, return the maximum sum obtained from any rectangle within the matrix.
Example:
Input:
1
4 5
1 2 -1 -4 -20
-8 -3 4 2 1
3 8 10 1 3
-4 -1 1 7 -6
Output:
29
Explanation:
The submatrix from (1,1) to (3,3) has the maximum sum of 29, illustrated as:
1 2 -1 -4 -20
-8 |-3 4 2 | 1
3 | 8 10 1 | 3
-4 |-1 1 7 | -6
Constraints:
1 ≤ T ≤ 10
1 ≤ M, N ≤ 100
-105 ≤ ARR[i] ≤ 105
Note: You do not need to print anything; implement the function to return the result only.

AnswerBot
4mo
Find the rectangle with the maximum sum of elements in a given matrix.
Iterate through all possible rectangles within the matrix and calculate the sum of each rectangle.
Keep track of the maximum sum en...read more
Help your peers!
Add answer anonymously...
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for Yodlee Software Developer Intern
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
C++ Interview Questions and Answers
150 Questions
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

