FastPrepMaximum All-Ones Square Side Length
Problems/Maximum All-Ones Square Side Length

Maximum All-Ones Square Side Length

Omnissa logoOmnissa● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Omnissa onsite interview for a full-time role. The report asks for the maximum square length in a matrix but does not keep the condition for a square to qualify. Here we assume a binary matrix and a square of all ones. We also chose the interface, the limits and the examples. This is not an exact rebuild of the question.

Our version is about 60% the same as the reported question.

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[][]) → int

Examples

Example 1

matrix = [[1,0,1,1],[1,1,1,1],[1,1,1,0]]return = 2
matrix
0123010111111121110

Rows 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 = 0
matrix
01000100

There are no one-cells, so no positive-size all-ones square exists.

Constraints

  • 1 <= matrix.length <= 50
  • 1 <= matrix[0].length <= 50
  • All rows have the same length.
  • Every matrix element is 0 or 1.

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
All Omnissa interview questionsSee Omnissa hiring insights
Saved
class Solution {
    public int largestSquare(int[][] matrix) {
        // Write your code here
    }
}
Checking account…