Maximal Rectangle
Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

30:00

Maximal Rectangle
hard
Topics
Companies

Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area.

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
Constraints:
  • rows==matrix.length\text{rows} == \text{matrix.length}

  • cols==matrix[i].length\text{cols} == \text{matrix}[i].\text{length}

  • 1rows,cols2001 \leq \text{rows}, \text{cols} \leq 200

  • matrix[i][j]\text{matrix}[i][j] is '0' or '1'.

Input
arr ={"matrix":[["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]}

Initialize heights array of size 6

Matrix

1

0

1

0

0

1

0

1

1

1

1

1

1

1

1

1

0

0

1

0

Heights Histogram (Row -1)
0
0
0
0
0
Max Area

0

Variables
No variables to display
DepthFunction Call
Stack empty
0/9