Dsa
Matrix
Medium
Maximal Rectangle of 1s
Given a binary matrix filled with 0s and 1s, find the size of the largest rectangle containing only 1s and return its area.
Input format: The first line contains two integers, N (the number of rows) and M (the number of columns). The next N lines each contain M integers (0 or 1).
Output format: A single integer representing the area of the largest rectangle.
Example:
Input:
4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
0 0 0 1 0
Output:
6
Key concepts
matrixrectanglemaximization
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now