145. Maximum Rectangle in Binary Matrix

HardArrayArray

Given a binary matrix filled with 0s and 1s, find the largest rectangle containing only 1s and return its area. Input: JSON 2D grid of 0/1.

Input: A JSON 2D 0/1 grid.

Output: Integer — maximum rectangle area.

Examples

Example 1
Input: [[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]]
Output: 6
Explanation: Largest all-ones rectangle has area 6.
Example 2
Input: [[1]]
Output: 1
Explanation: Single cell.
Example 3
Input: [[0]]
Output: 0
Explanation: No ones.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →