• + 0 comments

    My efficient java solution

        private static void printLargestSumOfHourglasses(List<List<Integer>> arr) {
            int result = -63;
            for (int row = 0; row < 4; row++) {
                for (int col = 0; col < 4; col++) {
                    int current = 0;
                    current += arr.get(row).subList(col, col + 3).stream().mapToInt(x -> x).sum();
                    current += arr.get(row + 1).get(col + 1);
                    current += arr.get(row + 2).subList(col, col + 3).stream().mapToInt(x -> x).sum();
                    
                    result = Math.max(result, current);
                }
            }
            System.out.println(result);
        }