Maximal Rectangle

Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True and return its area.

Example:

Given a matrix:

[
  [1, 1, 0, 0, 1],
  [0, 1, 0, 0, 1],
  [0, 0, 1, 1, 1],
  [0, 0, 1, 1, 1],
  [0, 0, 0, 0, 1]
]

return 6.

Analysis:

For each row i matrix[i][0...col-1] in the matrix, consider the longest length of consecutive 1 ending at matrix[i][j, j=[0...col-1] as the height of bar. This problem can be converted to Largest Rectangle In Histogram problem

results matching ""

    No results matching ""