You are viewing a single comment's thread. Return to all comments →
Simple Java Solution
public static int hourglassSum(List<List<Integer>> arr) { int biggest = Integer.MIN_VALUE; for(int i = 0; i < arr.size() - 2; i++){ for(int j = 0; j < arr.get(i).size() - 2; j++){ int count = 0; count += arr.get(i).get(j); count += arr.get(i).get(j + 1); count += arr.get(i).get(j + 2); count += arr.get(i + 1).get(j + 1); count += arr.get(i + 2).get(j); count += arr.get(i + 2).get(j + 1); count += arr.get(i + 2).get(j + 2); biggest = count >= biggest ? count : biggest; } } return biggest; }
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
Simple Java Solution