Find the area of the largest rectangle containing only 1s in a binary matrix.
Given a binary matrix of characters '0' and '1', find the area of the largest axis-aligned rectangle that contains only 1s.
You may choose any contiguous set of rows and columns, but every cell inside the rectangle must be 1.
Your task is to return the maximum possible area.
Input Format
- A binary matrix
matrixwithmrows andncolumns. - Each cell contains either
'0'or'1'.
Output Format
- Return a single integer: the maximum rectangle area consisting entirely of
1s.
Constraints
1 <= m, n- Cells are binary characters
'0'or'1'. - A valid rectangle must be contiguous and axis-aligned.
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
Explanation
The largest rectangle of 1s has area 6, formed by rows 2-3 and columns 1-3 (0-indexed in a 2x3 block of 1s).
Example 2
Input
matrix = [["0"]]
Output
0
Explanation
There is no rectangle containing only 1s.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.