• + 0 comments
    public static int hourglassSum(List<List<Integer>> arr) {
        // Write your code here
            int maxInteger = Integer.MIN_VALUE;
            for (int row = 0; row < arr.size() - 2; row++) {
                for (int col = 0; col < arr.get(row).size() - 2; col++) {
                    int topRow = arr.get(row).get(col) + arr.get(row).get(col + 1) + arr.get(row).get(col + 2);
                    int bottomRow = arr.get(row + 2).get(col) + arr.get(row + 2).get(col + 1) + arr.get(row + 2).get(col + 2);
                    int middleRow = arr.get(row + 1).get(col + 1);
                    maxInteger = Math.max(maxInteger, topRow + bottomRow + middleRow);
                }
            }
            return maxInteger;
        }