FastPrepLargest Square of Ones
Problems/Largest Square of Ones

Largest Square of Ones

OpenAI logoOpenAI● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an OpenAI online assessment for a full-time role. The report gives the goal of an all-ones square, a side length as the result, and a complete example. We added the number limits.

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

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

Examples

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 = 3
matrix
01234011010111111200111300111411000

The rows and columns from index 1 through 3 contain a 3 x 3 square of ones.

Example 2

matrix = [[0,0],[0,0]]return = 0
matrix
01000100

No cell contains 1.

Example 3

matrix = [[1]]return = 1
matrix
001

The 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 0 or 1.

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

Interview reports that mention this question

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int findLargestSquare(int[][] matrix) {
        // Write your code here.
    }
}
Checking account…