Search⌘ K
AI Features

Solution: Maximal Rectangle

Explore a dynamic programming approach to calculate the largest rectangle containing only 1s in a binary matrix. Understand how to convert each row into a histogram, track heights and boundaries using auxiliary arrays, and compute maximal rectangle areas efficiently. This lesson equips you with a clear method and the code to implement this solution with optimal time and space complexity.

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 ==== ...