Largest Square Subgrid Under a Sum Limit
Problem 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.
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.