AAlgoLab
ALG-H018HardMatrix

Largest Solid Rectangle

Return the area of the largest all-1 axis-aligned rectangle in a rectangular binary grid. Return 0 for an empty grid or no 1 cells.

Contract

input grid: integer[][]
return integer

Constraints

  • • Grid contains only 0 and 1
  • • All rows equal length

Examples

Example 1
grid = [[1, 0, 1, 0, 0], [1, 0, 1, 1, 1], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0]]
→ 6
Example 2
grid = [[0]]
→ 0

5 judge tests (2 shown above). Target complexity: O(rows*cols).