• + 0 comments

    Working answer static int hourglassSum(int[][] arr) { int rowCount = arr.length; int colIndex = 0; int rowIndex = 0; int total = 0; while(rowIndex < rowCount-2) { while(colIndex < arr[rowIndex].length-2) { int sum = 0; for(int i = rowIndex; i < rowIndex+3; i++) { if(i == rowIndex+1) { sum += arr[i][colIndex+1]; } else { for (int j = colIndex; j < colIndex+3; j++) { sum += arr[i][j]; } } } if(rowIndex == 0 && colIndex == 0) { total = sum; } else if (sum > total) { total = sum; } colIndex ++; } colIndex = 0; rowIndex ++; } return total; }