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
1y
The task is to find the maximum sum rectangle in a given matrix of integers.
Iterate through all possible rectangles in the matrix
Calculate the sum of each rectangle
Keep track of the maximum sum rectan...read more
Help your peers!
Add answer anonymously...
Texas Instruments Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Meeting Rooms Allocation Problem Statement Stark Industry is planning to organiz...read more
A Software Developer Intern was asked Q. Maximum Sum Rectangle Problem Given an M x N matrix of integers ARR, your task i...read more
A Software Developer Intern was asked Q. Josephus Problem Statement Consider 'N' individuals standing in a circle, number...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Meeting Rooms Allocation Problem Statement Stark Industry is planning to organiz...read more
A Software Developer Intern was asked Q2. Maximum Sum Rectangle Problem Given an M x N matrix of integers ARR, your task i...read more
A Software Developer Intern was asked Q3. Josephus Problem Statement Consider 'N' individuals standing in a circle, number...read more
>
Texas Instruments Software Developer Intern Interview 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

