MathWorksOA #22
Largest Sub-Grid
估计中等评测数据准备中,可先阅读题面
Given a square integer matrix grid and an integer maxSum, return the largest k such that there exists a k × k contiguous sub-grid whose sum is ≤ maxSum. If no 1 × 1 sub-grid qualifies, return 0.
Constraints
gridis ann × nmatrix,1 ≤ n ≤ 5000 ≤ grid[i][j] ≤ 10⁵1 ≤ maxSum ≤ 10¹⁰
Example 1
Input:
grid = [[2, 2, 2], [3, 3, 3], [4, 4, 4]]
maxSum = 4
Output:
0
Explanation:
Every 1 x 1 square in the last row sums to 4, but no larger square stays within the limit. Under the prompt's example, the maximum valid size is 0.