• + 0 comments
     public static int maxHourGlassValue(List<List<Integer>> arr){
            Integer result = Integer.MIN_VALUE;
            for(int i = 0; i < arr.size(); i++){
                List<Integer> inner_list = arr.get(i);
                for(int j = 0; j < inner_list.size(); j++){
                    try{
                        List<Integer> horizon_1 = arr.get(i-1);
                        List<Integer> horizon_2 = arr.get(i+1);
                        int calculated_value = inner_list.get(j) + horizon_1.get(j) + horizon_1.get(j-1) + horizon_1.get(j+1) + horizon_2.get(j) + horizon_2.get(j-1) + horizon_2.get(j+1);
                        if(calculated_value > result) result=calculated_value;
                    }catch(Exception e){
                        
                    }
                }
            }
            return result;
        }
        
    

    Avoided IndexOutOfBounds with try catch