Maximum All-Ones Square Side Length
Updated
Problem statement
Given a non-empty rectangular binary matrix matrix, return the largest side length of an axis-aligned square whose every cell is 1.
A square uses consecutive rows and consecutive columns. Its entire interior, not only its border, must contain ones. Return 0 if the matrix contains no ones. Return the side length, not the area; do not rotate the square.
Function
largestSquare(matrix: int[][]) → intExamples
Example 1
matrix = [[1,0,1,1],[1,1,1,1],[1,1,1,0]]return = 2Rows 1 through 2 and columns 0 through 1 form a 2-by-2 all-ones square (zero-based indices). Every possible 3-by-3 square contains a zero, so return side length 2.
Example 2
matrix = [[0,0],[0,0]]return = 0There are no one-cells, so no positive-size all-ones square exists.
Constraints
1 <= matrix.length <= 501 <= matrix[0].length <= 50- All rows have the same length.
- Every matrix element is
0or1.
More Omnissa Onsite Interview questions
- Build and Check a Palindrome Linked ListONSITE INTERVIEW · Seen Sep 2026
- Find the CelebrityONSITE INTERVIEW · Seen Sep 2026
- Maximum Subarray SumONSITE INTERVIEW · Seen Sep 2026
- Coin ChangeONSITE INTERVIEW · Seen Jul 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Jul 2026
- Rotate Array RightONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Minimum Path SumAmazon · ONSITE INTERVIEW
- Minimum Path SumMicrosoft · ONSITE INTERVIEWMicrosoft 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
- Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Longest Increasing Path in a MatrixVisa · ONSITE INTERVIEWVisa interview questions
- Maximal Rectangle in a Binary MatrixGoogle · ONSITE INTERVIEWGoogle interview questions
- Find Robots by Blocker DistancesUber · PHONE SCREENUber interview questions
- Largest Square of OnesOpenAI · OAOpenAI interview questions