You are viewing a single comment's thread. Return to all comments →
Java
public static int hourglassSum(List<List<Integer>> arr) { int hourGlassSum = 0; int maxHourGlassSum = Integer.MIN_VALUE; for(int i = 0; i < 4; i++){ for(int j = 0; j < 4; j++){ hourGlassSum = calculateHourGlass(arr, i, j); if(hourGlassSum > maxHourGlassSum){ maxHourGlassSum = hourGlassSum; } } } return maxHourGlassSum; } private static int calculateHourGlass(List<List<Integer>> arr, int i, int j) { int sum = 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); return sum; }
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
Java