Search⌘ K
AI Features

Solution: Maximal Rectangle

Explore how to apply dynamic programming to find the maximal rectangle composed entirely of 1s in a binary matrix. This lesson guides you through constructing histograms for each row, tracking height, left, and right boundaries, and calculating the largest rectangle area efficiently in O(m×n) time and O(n) space. You will understand how to optimize the problem using arrays to store intermediate results, enabling you to solve similar matrix-based algorithmic problems confidently.

Statement

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

Constraints:

  • rows ==== matrix.length

  • cols ==== ...