Search⌘ K
AI Features

Solution: Maximal Rectangle

Explore how to solve the maximal rectangle problem in a binary matrix by leveraging dynamic programming techniques. Understand how to build histograms from matrix rows and use arrays to track heights and boundaries. This lesson guides you through calculating the largest rectangle area with time and space efficient methods.

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 ==== matrix[i].length

  • 11 \leq rows, cols 200\leq 200 ...