Maximum Rectangle

Given a 2D binary matrix of integers A containing 0’s and 1’s of size N x M.

Find the largest rectangle containing only 1’s and return its area.

Note: Rows are numbered from top to bottom and columns are numbered from left to right.



Input Format

The only argument given is the integer matrix A.

Output Format

Return the area of the largest rectangle containing only 1's.

Constraints

1 <= N, M <= 1000
0 <= A[i] <= 1

For Example

Input 1:
    A = [   [0, 0, 1]
            [0, 1, 1]
            [1, 1, 1]   ]
Output 1:
    4

Input 2:
    A = [   [0, 1, 0, 1]
            [1, 0, 1, 0]    ]
Output 2:
    1
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Maximum Rectangle on Interview Code Editor
Sign Up
to access hints and editorial solutions for Maximum Rectangle

Discussion


Loading...
Click here to start solving coding interview questions