Maximum Size Rectangle Binary Sub-Matrix with All 1s
Given a binary-valued matrix of size N x M
, your task is to determine the largest area of a submatrix that contains only 1's.
Input:
The first line contains an integer 'T', the number of test cases.
Each test case begins with a line containing two integers, 'N' and 'M', representing the number of rows and columns of the matrix, respectively.
This is followed by 'N' lines, each containing 'M' binary integers (0 or 1) representing the matrix.
Output:
An integer, representing the maximum area of a submatrix that consists entirely of 1's, for each test case, printed on a separate line.
Example:
Input:
2
4 4
0 1 1 0
1 1 1 1
1 1 1 0
0 1 0 0
3 3
1 0 1
0 1 0
1 1 1
Output:
6
3
Explanation:
In the first test case, the maximum 1's submatrix covers an area of 6 (2 rows by 3 columns).
In the second test case, the maximum 1's submatrix covers an area of 3 (1 row by 3 columns).
Constraints:
1 <= 'T' <= 50
1 <= 'N', 'M' <= 100
Time Limit: 1 second
![](https://static.ambitionbox.com/alpha/community/assets/no-posts.png)
Be the first one to answer
Add answer anonymously...
Top Dunzo SDE-2 interview questions & answers
Popular interview questions of SDE-2
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