Maximal Rectangle in a Binary Matrix
Problem statement
Given a rectangular binary matrix matrix, return the area of the largest axis-aligned rectangle composed only of 1 values.
A rectangle may span any positive number of consecutive rows and columns. Return 0 when the matrix contains no 1.
Function
maximalRectangle(matrix: int[][]) → intExamples
Example 1
matrix = [[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]]return = 6The largest all-one rectangle has height 2 and width 3.
Example 2
matrix = [[0]]return = 0No all-one rectangle exists.
Example 3
matrix = [[1,1],[1,1]]return = 4The entire matrix is an all-one rectangle of area 4.
Constraints
1 <= matrix.length <= 200.1 <= matrix[i].length <= 200.- Every row has the same length.
- Every value is either
0or1.