• + 0 comments

    Java solution:

    				...
    
            int maxSum = Integer.MIN_VALUE;
            
            for (int i = 0; i <= arr.size() - 3; i++) {
                for (int j = 0; j <= arr.size() - 3; j++) {
                    int currentSum = calcSum(i, j, arr);
                    if (currentSum > maxSum) {
                        maxSum = currentSum;
                    }
                }
            }
    				...
    
        private static int calcSum(int vEdge, int hEdge, List<List<Integer>> arr) {
            int[][] hourGlassCooridnates = {{0, 0}, {0, 1}, {0, 2}, {1, 1}, {2, 0}, {2, 1}, {2, 2}};   
            int sum = 0;
            for (int[] coordinate : hourGlassCooridnates) {
                int i = coordinate[0];
                int j = coordinate[1];
                sum += arr.get(vEdge + i).get(hEdge + j);
            }
            return sum;
        }