Maximal Rectangle
Given a binary matrix filled with '0' and '1' characters, find the largest rectangle containing only '1's and return its area.
Open official problem prompt ↗Find the biggest solid block of 1's anywhere in the grid, measured by area.
Stack transparent sheets one row at a time. On each new sheet, a column of 1's grows taller wherever the ground below is also 1; a 0 knocks that tower flat. The biggest shadow the towers cast on any single sheet is the answer.
- Input
- matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
- Output
- 6
- Why
- The block of 1's spanning columns 2-4 across rows 1-2 (and the reinforcing row 3 columns 2-3) yields a 2 x 3 rectangle of area 6.
rows == matrix.lengthcols == matrix[0].length1 <= rows, cols <= 200matrix[i][j] is '0' or '1'