public static int hourglassSum(List<List<Integer>> arr) { int rows = arr.size(); // Corrected to use size() for List int col = arr.get(0).size(); // Corrected to use size() for List inside List int maxSum = Integer.MIN_VALUE; // Corrected variable naming for (int i = 0; i < rows - 2; i++) { for (int j = 0; j < col - 2; j++) { int currSum = arr.get(i).get(j) + arr.get(i).get(j + 1) + arr.get(i).get(j + 2) + arr.get(i + 1).get(j + 1) + arr.get(i + 2).get(j) + arr.get(i + 2).get(j + 1) + arr.get(i + 2).get(j + 2); maxSum = Math.max(currSum, maxSum); } } return maxSum; }
u seriously explained so well!! great learning and teaching skills ..please solve more problems ,so that it could help us ... videos take time to get popularized..but dont stop to teach ...all the best
In line 14, just replace the loop with a loop like: for(ArrayList<Integer> query : queries) { int a=query.get(0); int b=query.get(1); int k=query.get(2); .................................................. .................................................. } //Rest code will be same