hardStack / QueuePure DSA~42 min
Largest All-Healthy Rectangle in a Status Grid
A monitoring dashboard renders a grid where each cell is 1 (healthy) or 0 (degraded). Find the area of the largest axis-aligned rectangle containing only healthy cells.
Problem
Given a rows x cols binary matrix filled with 0s and 1s, find the largest rectangle containing only 1s and return its area.
Input
A 2D matrix of characters '0'/'1' (or integers 0/1), with rows in [1, 200] and cols in [1, 200].
Output
An integer: the maximum all-ones rectangle area.
Constraints
- rows == matrix.length, cols == matrix[0].length
- 1 <= rows, cols <= 200
- matrix[i][j] is '0' or '1'.
Examples
Example 1
Input
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
Output
6
The 2x3 block of 1s in the lower-middle has area 6.
Example 2
Input
matrix = [["0"]]
Output
0
No healthy cell.