FastPrepLargest All-One Square Area and Count
Problems/Largest All-One Square Area and Count

Largest All-One Square Area and Count

NVIDIA logoNVIDIA● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA phone screen for a new grad role. The report asks for the maximum matrix area and the number of times it occurs. Replies leave the shape uncertain, so here we use squares made only of ones. The report leaves out the cell rules, the limits, and what to return when there is none.

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

Given a rectangular binary matrix matrix, find the largest nonempty square containing only 1 cells and count how many squares have that maximum area.

A square uses consecutive rows and consecutive columns with the same positive side length. Count each distinct top-left coordinate and side length once. Overlapping squares count separately.

Return [maximumArea, numberOfMaxima] in that order. Only squares with the largest area contribute to the count. If the matrix has no rows, no columns, or no 1 cells, return [0, 0].

Function

largestSquareAreaAndCount(matrix: int[][]) → int[]

Examples

Example 1

matrix = [[1,1,1],[1,1,1]]return = [4,2]
matrix
01201111111

The two squares with side length 2 start at (0, 0) and (0, 1). They overlap and each has area 4. The six smaller squares do not contribute to the count.

Example 2

matrix = [[1,0,1],[0,1,0]]return = [1,3]
matrix
01201011010

Each of the three 1 cells is a square with area 1. No larger square is entirely ones.

Example 3

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

No nonempty all-one square exists, so both the maximum area and its count are 0.

Constraints

  • 0 <= matrix.length <= 100.
  • Every row has the same length, between 0 and 100 inclusive.
  • Every cell is 0 or 1.

More NVIDIA Phone Screen questions

  • Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
  • Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
  • Maximum Subarray SumCapital One · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Variance Sum SplitAirbnb · PHONE SCREEN
  • Minimum Cost to Merge StonesGoogle · PHONE SCREEN · ONSITE INTERVIEW
  • Maximum Game Score with Fixed Forward JumpsStripe · OA
  • Maximum Apples from Two Disjoint Fixed-Length SegmentsMarshall Wace · OA
  • Maximum Non-Decreasing Array LengthVisa · OA
  • Maximize CollaborationTikTok · OA
  • Maximum Sum RectangleDeloitte · OA
  • Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREEN
See NVIDIA hiring insights
Saved
class Solution {
    public int[] largestSquareAreaAndCount(int[][] matrix) {
        // Return the maximum square area and the number of squares having it.
    }
}
Checking account…