Maximum Size Rectangle Sub-matrix with All 1's Problem Statement

You are provided with an N * M sized binary matrix 'MAT' where 'N' denotes the number of rows and 'M' denotes the number of columns. Your task is to determine and return the maximum area of a submatrix comprised entirely of 1's, i.e., the largest area of a submatrix where every element is '1'.

Example:

Input:
2
4 4
1 0 1 1
1 1 1 1
0 1 1 0
1 1 1 0
3 3
1 0 1
1 1 1
0 1 0
Output:
4
3
Explanation:

For the first test case, the maximum submatrix of all 1's has an area of 4. For the second test case, the maximum submatrix of all 1's has an area of 3.

Constraints:

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

Note:

  • Each cell in the binary matrix will have a value of either 0 or 1.
  • A submatrix is defined by selecting specific rows and columns from a larger matrix.
  • The area of a submatrix with 'h' rows and 'w' columns is h * w.
  • You don't need to print the output; the function will handle the computation and return the result accordingly.
AnswerBot
4mo

Find the maximum area of a submatrix with all 1's in a binary matrix.

  • Iterate over each cell in the matrix and calculate the maximum area of submatrix with that cell as the top-left corner.

  • Use dynamic ...read more

Help your peers!
Select
Add answer anonymously...

Hike Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Infix to Postfix Conversion Convert a given infix expression, represented as a s...read more
A Software Developer Intern was asked Q. Maximum Difference in Matrix Given an n x n matrix mat[n][n] of integers, find t...read more
A Software Developer Intern was asked Q. Maximum Size Rectangle Sub-matrix with All 1's Problem Statement You are provide...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Infix to Postfix Conversion Convert a given infix expression, represented as a s...read more
A Software Developer Intern was asked Q2. Maximum Difference in Matrix Given an n x n matrix mat[n][n] of integers, find t...read more
A Software Developer Intern was asked Q3. Maximum Size Rectangle Sub-matrix with All 1's Problem Statement You are provide...read more
Hike Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
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