Maximal Rectangle in a Binary Matrix
Updated
Problem statement
Given a rectangular binary matrix matrix, return the area of the largest axis-aligned rectangle composed only of 1 values.
A rectangle may span any positive number of consecutive rows and columns. Return 0 when the matrix contains no 1.
Function
maximalRectangle(matrix: int[][]) → intExamples
Example 1
matrix = [[1,0,1,0,0],[1,0,1,1,1],[1,1,1,1,1],[1,0,0,1,0]]return = 6The largest all-one rectangle has height 2 and width 3.
Example 2
matrix = [[0]]return = 0No all-one rectangle exists.
Example 3
matrix = [[1,1],[1,1]]return = 4The entire matrix is an all-one rectangle of area 4.
Constraints
1 <= matrix.length <= 200.1 <= matrix[i].length <= 200.- Every row has the same length.
- Every value is either
0or1.
More Google Onsite Interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Dungeon GameAmazon · ONSITE INTERVIEW
- Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Longest Increasing Path in a MatrixVisa · ONSITE INTERVIEWVisa interview questions
- Trapping Rain WaterMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Maximum All-Ones Square Side LengthOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Minimum Path SumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Bomb Enemy Best CoordinatesSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions
- Largest Square of Ones in a GridExpedia · ONSITE INTERVIEWExpedia interview questions
- Cherry PickupInfosys · OAInfosys interview questions
- Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions