Search⌘ K
AI Features

Solution: Maximal Rectangle

Explore a dynamic programming approach to find the largest rectangle containing only 1s in a binary matrix. This lesson teaches how to transform each row into a histogram, track heights and boundaries, and compute the maximal rectangle area with an efficient O(m×n) time complexity algorithm.

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