• + 0 comments

    here's a method much cleaner for List input

    private static int printMaxSum(List<List<Integer>> matrix){
            int ans=Integer.MIN_VALUE;
            for(int i=0;i<=3;i++){
                
                List<Integer> row1 = matrix.get(i);
                List<Integer> row2 = matrix.get(i+1);
                List<Integer> row3 = matrix.get(i+2);
                for(int j=0; j<=3;j++){
                    int sum=row1.get(j+0)+row1.get(j+1)+row1.get(j+2)
                    +row2.get(j+1)+row3.get(j+0)+row3.get(j+1)+row3.get(j+2);
                    if(sum>ans)
                        ans=sum;
                }
            }
            return ans;
        }