• + 0 comments
     public static int hourglassSum(List<List<int>> arr)
        {
            int sum=0;
            int max = 0;
            int f =1;
            for(var i=1; i<5;i++) {
                 for(var j=1; j<5;j++) {
                    sum = arr[i][j] + arr[i-1][j-1]+arr[i-1][j]+arr[i-1][j+1]
                    +arr[i+1][j-1]+arr[i+1][j]+arr[i+1][j+1];
                    if( f==1) {
                        max = sum;
                        f = 0;
                    }
                    
                    if(max < sum) max = sum;
                 }
            }
            return max;
    
        }