grid of non-negative integers and a number limit. Call a square block of the table light if the sum of all its numbers does not exceed limit.
Return the side length of the largest light square, or 0 if not even a 1×1 square is light.grid=[[3, 1, 1], [1, 1, 1], [1, 1, 5]], limit=4 → 2
The 2×2 square in the top-right corner is four ones, summing to 4, exactly the limit. The only 3×3 square is the whole grid with sum 15, which is too heavy.
grid=[[7, 8], [9, 6]], limit=5 → 0
Even every single cell exceeds 5, so no square fits and the answer is 0.
grid.length, grid[i].length ≤ 600grid[i][j] ≤ 10⁴limit ≤ 10⁵grid=[[3, 1, 1], [1, 1, 1], [1, 1, 5]], limit=4
2
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.