Search⌘ K
AI Features

Solution: Maximal Rectangle

Explore how to solve the maximal rectangle problem using dynamic programming by transforming each row into a histogram. Understand how to track heights and boundaries to compute the largest rectangle of 1s in a binary matrix. This lesson helps you implement an O(m × n) time and O(n) space complexity solution to optimize your coding interview problem-solving skills.

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