Maximum Size Rectangle Sub-Matrix with All 1's

Given an N x M binary matrix 'MAT', where N is the number of rows and M is the number of columns, determine the maximum area of a submatrix consisting entirely of 1's. Each cell in the submatrix must have the value 1.

Example:

Input:
T = 1
Matrix = [[0, 1, 1, 0], [1, 1, 1, 1], [0, 1, 1, 1]]
Output:
6
Explanation:

The largest area submatrix of all 1's is in the second and third rows, with an area of 6.

Constraints:

  • 1 <= T <= 50
  • 1 <= N, M <= 100
  • Time Limit: 1 second

Note:

  • A binary valued matrix contains only 0s and 1s.
  • A submatrix is formed by selecting specific rows and columns from the larger matrix.
  • The area of a matrix with 'h' rows and 'w' columns is equal to h * w.

Input:

The first line contains an integer 'T' representing the number of test cases.
For each test case, the first line contains two space-separated integers 'N' and 'M'.
Each of the next N lines contains M space-separated integers, representing the binary matrix.

Output:

For each test case, print a single line indicating the maximum area of a submatrix consisting entirely of 1's.
Be the first one to answer
Add answer anonymously...
Hike Software Developer Intern 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