Largest All-One Square Area and Count
Updated
Problem statement
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]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]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]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
0and100inclusive. - Every cell is
0or1.
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