611. Maximal Rectangle in Binary Matrix

MediumStackMonotonic StackDynamic Programming

Given a binary matrix of 0s and 1s, return the area of the largest rectangle containing only 1s. The input is JSON {matrix}.

Input: JSON {matrix}.

Output: Integer — the largest all-ones rectangle area.

Examples

Example 1
Input: {"matrix":[[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]]}
Output: 6
Explanation: A 2x3 block of ones.
Example 2
Input: {"matrix":[[0]]}
Output: 0
Explanation: No ones.
Example 3
Input: {"matrix":[[1]]}
Output: 1
Explanation: A single one.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →