Search⌘ K
AI Features

Solution: Maximal Rectangle

Explore the dynamic programming approach to identify the largest rectangle consisting only of ones in a binary matrix. This lesson helps you understand how to transform each row into a histogram and use arrays to track heights and boundaries, enabling efficient calculation of the maximal rectangle area. You'll gain skills to solve similar optimization problems in coding interviews.

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