Largest Square of Ones
Updated
Problem statement
Given a rectangular binary matrix matrix, return the side length of the largest square submatrix composed only of 1 values.
If the matrix contains no 1, return 0.
Function
findLargestSquare(matrix: int[][]) → intExamples
Example 1
matrix = [[1,1,0,1,0],[1,1,1,1,1],[0,0,1,1,1],[0,0,1,1,1],[1,1,0,0,0]]return = 3The rows and columns from index 1 through 3 contain a 3 x 3 square of ones.
Example 2
matrix = [[0,0],[0,0]]return = 0No cell contains 1.
Example 3
matrix = [[1]]return = 1The single cell is itself a square of side length 1.
Constraints
1 <= matrix.length <= 500.1 <= matrix[i].length <= 500.- Every row has the same length.
- Every value is either
0or1.
More OpenAI Online Assessment questions
- Count Routes Through Four Shop TypesOA · Seen Oct 2026
- Digit-Sum Sequence Join PointOA · Seen Oct 2026
- Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026
- Password Clues and the Next CommandOA · Seen Oct 2026
- Longest Increasing Price SubsequenceOA · Seen Oct 2026
- Macaron Order PriceOA · Seen Oct 2026
- Shortest Atom Action PathOA · Seen Oct 2026
- Simplify a Quadratic ExpressionOA · Seen Oct 2026
- Minimum-Cost Color SequenceOA · PHONE SCREEN · Seen Oct 2026
- Largest Microorganism After ConsumptionOA · Seen Oct 2026
Similar questions at other companies
- Largest Plus SignxAI · OAxAI interview questions
- Cherry PickupInfosys · OAInfosys interview questions
- Maximum Sum RectangleDeloitte · OADeloitte interview questions
- Maximal SquareAmazon · ONSITE INTERVIEW
- Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
- Factory Cost — Minimum Cost Across StagesStripe · PHONE SCREENStripe interview questions
- Maximum All-Ones Square Side LengthOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Maximum Rocks on a North-or-East Grid PathGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
- Maximal SquareAirwallex · PHONE SCREENAirwallex interview questions
- Maximal SquareSalesforce · PHONE SCREENSalesforce interview questions