Interview Preparation Kit/Arrays/2d_array-ds.cpp
// Complete the hourglassSum function below.

Complete the hourglassSum function below.
Complete the hourglassSum function below .
int hourglassSum(vector<vector<int>> arr) {
    int top_row, bottom_row, temp_sum, max_sum;
    max_sum = numeric_limits<int>::min();
    for (int i = 0; i < 4; ++i){
        for (int j = 0; j < 4; ++j){
            top_row = arr[i][j] + arr[i][j+1] + arr[i][j+2];
            bottom_row = arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2];
            temp_sum = top_row + bottom_row + arr[i+1][j+1];
            if (temp_sum > max_sum) max_sum = temp_sum;
            cout << temp_sum << endl;
        }
    }
    return max_sum;
}
int hourglassSum ( vector < vector < int > > arr ) { int top_row , bottom_row , temp_sum , max_sum ; max_sum = numeric_limits < int > :: min ( ) ; for ( int i = 0 ; i < 4 ; ++ i ) { for ( int j = 0 ; j < 4 ; ++ j ) { top_row = arr [ i ] [ j ] + arr [ i ] [ j + 1 ] + arr [ i ] [ j + 2 ] ; bottom_row = arr [ i + 2 ] [ j ] + arr [ i + 2 ] [ j + 1 ] + arr [ i + 2 ] [ j + 2 ] ; temp_sum = top_row + bottom_row + arr [ i + 1 ] [ j + 1 ] ; if ( temp_sum > max_sum ) max_sum = temp_sum ; cout << temp_sum << endl ; } } return max_sum ; }
Complete the hourglassSum function below.
Complete the hourglassSum function below .
// Traverse by column first then to the next row.
 // Subtract the length and width for loop 
 // by 2 due to the hourglass shape.
