Problem · Matrix
Largest Square Subgrid Under a Sum Limit
Learn this problemProblem statement
You are given a two-dimensional integer array grid and an integer maxSum.
For a side length k, consider every contiguous k x k square subgrid. The side length is valid when the sum of every such square is at most maxSum.
Return the maximum valid side length.
Source note: The report clearly described the array, the sum limit, and the requirement that every square of the chosen size satisfy the limit. This version is a close reconstruction of that core task; the original example, function signature, and numeric limits were not included.
Function
largestSquareSubgrid(grid: int[][], maxSum: int) → intExamples
Example 1
grid = [[1,1,1],[1,1,1],[1,1,1]]maxSum = 4return = 2Every 2 x 2 square has sum 4, while the only 3 x 3 square has sum 9. Therefore the largest valid side length is 2.
More OpenAI problems
- Memory AllocatorPHONE SCREEN · Seen Jul 2026
- Message Event AggregationONSITE INTERVIEW · Seen Jul 2026
- Plant Infection Simulation, Part 4: Death CountdownPHONE SCREEN · Seen Jun 2026
- Streaming Entropy, Part 1: Batch EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 2: Numerically Stable EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 3: Block-wise EntropyONSITE INTERVIEW · Seen Jun 2026
- Streaming Entropy, Part 4: Stable Streaming EntropyONSITE INTERVIEW · Seen Jun 2026
- Resumable List IteratorPHONE SCREEN · Seen Jun 2026