Skip to content
CodeShare
All problems

Maximal Rectangle

Find the largest rectangle made only of 1s in a grid.

HardStackDynamic programmingMatrix

Given a rows × cols grid matrix filled with the characters 0 and 1, return the area of the largest rectangle containing only 1s.

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
Example 2
Input
matrix = [["0"]]
Output
0
Example 3
Input
matrix = [["1"]]
Output
1

Constraints

  • 1 <= rows, cols <= 200
  • Each matrix[i][j] is 0 or 1, as a one-character string.