• + 0 comments

    Here is my c++ solution you can watch video explanation here : https://www.youtube.com/watch?v=aJv6KLHL3Qk

    int hourglassSum(vector<vector<int>> arr) {
        int result = -63;
        for(int r = 1; r <= 4; r++){
            for(int c = 1; c <= 4; c++){
              int s = arr[r][c] + arr[r-1][c] + arr[r-1][c-1] + arr[r-1][c+1];
              s += arr[r+1][c] + arr[r+1][c-1] + arr[r+1][c+1];
              result = max(result,s);
            }
        }
        
        return result;
    }