FastPrepLargest Square of 1's
Problems/Largest Square of 1's

Largest Square of 1's

FactSet logoFactSet● MediumOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

A quality agent is responsible for inspecting samples of the finished products in the production line. Each sample contains defective and non-defective products represented by 1 and 0 respectively. The product samples are placed sequentially in a two-dimensional square matrix. The goal is to determine the size of the largest square of defective products in the two-dimensional square matrix.

Each line i of the n subsequent lines (where 0 ≤ i < n) contains n space-separated integers that describe samples[i].

Function

largestSquareOfOnes(samples: int[][]) → int

Complete the function largestSquareOfOnes in the editor.

largestSquareOfOnes has the following parameter:

  1. int[][] samples: a two-dimensional array of integers representing the product samples

Returns int: the size of the largest square of defective products

Examples

Example 1

samples = [[1,1,1,1,1],[1,1,1,0,0],[1,1,1,0,0],[1,1,1,0,0],[1,1,1,1,1]]return = 3
Example 1 illustration

The first square of defective products is a sub-matrix 3 x 3 starting at (0,0) and ending at (3,3). The second square of defective products is also a sub-matrix 3 x 3 at (1,0), and ending at (4,3). The third square of defective products is also a sub-matrix 3 x 3 at (2,0), and ending at (5,3). The size of the largest square of defective products is 3.

Example 2

samples = [[1,1,1],[1,1,0],[1,0,1]]return = 2
Example 2 illustration

The first square of defective products is a sub-matrix 2 x 2 starting at (0,0) and ending at (1,1). The other square of defective products are a sub-matrix 1 x 1 at (2,0), (0,2), and (2,2). The size of the largest square of defective products is 2.

Example 3

samples = [[0,1,1],[1,1,0],[1,0,1]]return = 1
Example 3 illustration

All square of defective products are a sub-matrix 1 x 1 at (0,1), (0,2), (1,0), (1,1), (2,0), and (2,2). The size of the largest square of defective products is 1.

Constraints

  • 🥑🥑

More FactSet interview questions

  • Last Stone WeightOA · Seen Sep 2024
  • Photo AlbumOA · Seen Sep 2024

Similar questions at other companies

  • Grid Paths with Override PassesIMC Trading · OAIMC Trading interview questions
  • Largest Square of OnesOpenAI · OAOpenAI interview questions
  • Grid Paths with Override PassesMicrosoft · OAMicrosoft interview questions
  • Minimum Moves to Spread Stones Across a GridAmerican Express · OAAmerican Express interview questions
  • Maximum Reward (Intuit India)Intuit · OAIntuit interview questions
  • Largest Plus SignxAI · OAxAI interview questions
  • Calculate the Max ValueAmazon · OA
  • Longest Border-Ending Diagonal PatternZipRecruiter · OAZipRecruiter interview questions
  • Count Grid Words with One TurnCapital One · OACapital One interview questions
  • Minimum Falling Path SumScale AI · OAScale AI interview questions
All FactSet interview questionsSee FactSet hiring insights
Saved
class Solution {
    public int largestSquareOfOnes(int[][] samples) {
      // write your code here
    }

}
Checking account…