You are viewing a single comment's thread. Return to all comments →
Java solution
class Result { public static int hourglassSum(List<List<Integer>> arr) { List<Integer> hourglassList = new ArrayList<>(); for(int i=0; i<arr.size()-2;i++){ for(int j=0; j<arr.size()-2;j++){ int one = arr.get(i).get(j); int two = arr.get(i).get(j+1); int three = arr.get(i).get(j+2); int four = arr.get(i+1).get(j+1); int five =arr.get(i+2).get(j); int six=arr.get(i+2).get(j+1); int seven = arr.get(i+2).get(j+2); int hourglass = List.of(one,two,three,four,five,six,seven).stream().mapToInt(x -> x).sum(); hourglassList.add(hourglass); } } return hourglassList.stream().max((x,y) -> x.compareTo(y)).get(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
Java solution