O D 1 2 Sub-Grid Given a square grid of integers and an integer value, maxSum, determine the maximum size of the square
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
O D 1 2 Sub-Grid Given a square grid of integers and an integer value, maxSum, determine the maximum size of the square
mum 2x2 grid has a sum of 14. If 4 s maxSum < 14, the maximum size of the square sub-grid is 1. 2 3 4 2 3 4 2 2 3 3 4 4 2 3 4 2 2 32 3 4 2 2 3. 2 3 2 3 3 4 4 4 4 2 x 2 Sub-grids Maximum sub-grid sum = 14 (3+3+4+4=14) 2 2 3 3 4 4 3. The maximum 3x3 grid has a sum of 27. size of the square sub-grid is 2. 4 3x3 Sub-grids Maximum sub-grid sum-27 (2+2+2+3+3+3+4+4+4-27) 2 3 4 2 3 4 12 If 14 s maxSum < 27, the maximum 4. If maxSum 227, the entire grid satisfies the condition so the answer is 3. Vis Test
+ 4 3 x 3 Sub-grids Maximum sub-grid sum=27 (2+2+2+3+3+3+4+4+4=27) 4. If maxSum ≥ 27, the entire grid satisfies the condition so the answer is 3. Function Description Complete the function largestSubgrid in the editor below. largestSubgrid has the following parameter(s): int maxSum: an integer, the maximum acceptable sum of any sub-grid int grid[n][n]: an nx narray where grid[][] is the value of the cell in the throw and th column Returns: should return 0. int: an integer that denotes the largest integer k such that there is no kx ksub-grid with a total value greater than maxSum. If all square sub-grids have value greater than maxSum, the function Constraints 1sns1550 1 s maxSum ≤ 10⁹ 1 ≤ grid[][] ≤ 107 the sum of any entire grid is s 10⁹ Input Format for Custom Testing Sample Case 0 Sample Input 0 STR