ETA Can't read the text? Switch theme 3. Largest Sub-Grid Given a square grid of integers and an integer value, maxSum,
Posted: Sun Jul 10, 2022 11:26 am
left O LL 1 2. The maximum 2x2 grid has a sum of 14. If 4 s maxSum < 14, the maximum size of the square sub-grid is 1. 2 2 2 3 3 3 4 4 4 @N 2 2 3 4 34 2 2 3 3 4 2 2 2 3 4 2x2 Sub-grid Maximum esb-grid sum-14 2 2 2 3 3 3 4 4 4 3. The maximum 3x3 grid has a sum of 27. If 14 s maxsum 27, the maximum size of the square sub-grid is 2. 2 2 3 3 3 4 4 4 23 4 4 daum-21 343 Sub grads Mamun 02-2-2-343-3-4-4-4-27) 4. If maxum 27, the entire grid satisfies the condition so the answer is Ⓒ Ing 14 15 16 17 18 19 20 21 22 23 24 25 28 29 30 Java 15 Autocomplete Ready 31 32 26 27 ) a 34 35 37 36 class Result ( . Complete the largestSubgrid' function below. The function is expected to return an INTEGER. The function accepts following parameters: . 1. 20 INTEGER ARRAY grid . 2. INTEGER maxSum public static int TargestSubgrid(ListeListInteger>> grid, int maxsus) ( ) public class Solution ( public static void main(String[] args) throws TOException ( Bufferediteader bufferedleader new BufferedReader (new InputStreamleader (System.in)); Bufferedwriter bufferedwriter w Bufferedwriter (new FileWriter(System.getenv ("OUTPUT_PATH">)); int gridRows Integer.parseInt(bufferedReader. readLine().trin()); fnt gridcolumns Integer.parseInt(bufferedReader. readLine().trin()); Test Results Custom Input
left LLL 2 Function Description Complete the function largestSubgrid in the editor below. largestSubgrid has the following parameter(s): int grid[n][n): an nxnarray where grid is the value of the cell in the Arow and column int maxsum: an integer, the maximum acceptable sum of any sub-grid Returns: int: an integer that denotes the largest integer k such that there is no kxksub-grid with a total value greater than maxSum. If all square sub-grids have value greater than maxsum, the function should return 0. Constraints • 1sns1550 • 1 s maxSums 10⁰ • 1sgrids 107 the sum of any entire grid is s 10 Input Format for Custom Testing Sample Case Ⓒ Sample Input o STOIN Function + 111. 111 grid[n][n] n=3 grid [[1,1,1), (1,3,3), (1,1,1)) maxSun - 4 Sample Output 0 36 14 32 34 35 15 21 22 Infa Java 15 Autocomplete Ready Ⓒ class Result ( 16 17 18 19 20 23 24 25 26 27 28 29 30 31 . Complete the largestSubgrid' function be The function is expected to return an INZ The function accepts following parameters 1. 20 INTEGER ARRAY grid 2. INTEGER maxSum . "/ J public static int largestSubgrid(ListeList> grid, int maxSun) { } public class Solution ( public static void main(String[] args) throws IOException ( BufferedReader bufferedReader new BufferedReader(new InputStreaniteader (Systen.in)); Bufferedwriter bufferedwriter now BufferedWriter(new Filewriter (Systen.getenv("OUTPUT_PATH"))); int gridRows = Integer.parseInt(bufferedReader.readLine().trim()); int gridColumns Integer.parseInt(buffered leader.readLine().trim()); ListeList> grid new ArrayList(); Intstream.range(e, gridRows).forEach(1>{ try ( B -30% grid.add( Stream.of (bufferedReader.readLine().replaceAt("\\$", "").split("")) .nap (Integer:1parmeint) .collect(telist()) Line: 28 Col. 1 U