Asked inDunzo,SDE-2

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

Be the first one to answer
Add answer anonymously...
Dunzo SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
Awards 2025
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits
Stay ahead in your career with AmbitionBox app