Maximal Rectangle

DP on Squares DSA practice problem on Onlearn.

Difficulty: hard.

Topics: Finding the Largest Rectangle Containing Only 1's in a Binary Matrix, Matrices, Dynamic Programming, Stack, Monotonic Stack, Arrays, Time Complexity, Space Complexity, dynamic programming, matrix manipulation, stack, frequency counting, stack algorithms, time complexity analysis, Largest Rectangle in Histogram, DP Advanced Techniques.

Largest Rectangle in Binary Matrix Problem Statement Given an rows x cols binary matrix matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Input Specification matrix: A list of lists of integers, where each inner list represents a row of the binary matrix. Each element will be either 0 or 1. Output Specification Return an integer representing the area of the largest rectangle containing only 1's. Constraints Implicitly, rows = 1, cols = 1. The specific ranges for rows and cols or matrix dimensions are not provided, but assume they are within standard competitive programming limits. Sample Test Cases Example 1: Input: Output: Explanation: The highlighted part in the original content (corresponding to matrix[1][2] to matrix[3][4]) depicts the rectangle with the largest area, which is 6. Example 2: Input: Output: Explanation: In this case, there is only one rectangle with area 1.