You are viewing a single comment's thread. Return to all comments →
static void printMaxHourglassSum(List> arr){ //System.out.println("arr " + (arr.get(0)).get(0));
ArrayList<Integer> arrSum = new ArrayList<>(); for(int row=0; row<6; row++){ for(int col=0; col<6; col++){ //System.out.println("row: " + row + ", col: " + col); int skipIdx = 0; int temp = 0; if(row<=3 && col<=3) { for(int i=row; i<row+3; i++){ for(int j=col; j<col+3; j++){ skipIdx++; //System.out.println("idx: " + idx); // System.out.println("i: " + i // + ", j: " + j // + "= " + (arr.get(i)).get(j)); if(skipIdx==4 ||skipIdx==6){ continue; } temp += (arr.get(i)).get(j); } } //System.out.println("temp: " + temp); arrSum.add(temp); } } } for(int i=0; i<arrSum.size(); i++){ //System.out.println("arrSum: " + arrSum.get(i)); } Collections.sort(arrSum); System.out.println(arrSum.get(arrSum.size()-1)); }
Seems like cookies are disabled on this browser, please enable them to open this website
Java 2D Array
You are viewing a single comment's thread. Return to all comments →
static void printMaxHourglassSum(List> arr){ //System.out.println("arr " + (arr.get(0)).get(0));