• + 0 comments
    int sum = 0;
        sum += 2 * A.size() * A[0].size(); // it will check count all the top bottom of the stack
        
        for(int i = 0; i< A.size(); i++){
            for(int j = 0; j< A[0].size(); j++){
                
                //it checks, is there any board on north direction or not
                if(i == 0){
                     sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i-1][j]);
                }
                
                // it checks, is there any board on south direction or not
                if(i == A.size()-1){
                     sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i+1][j]);
                }
                
                //it checks, is there any board on west direction or not
                if(j == 0){
                    sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i][j-1]);
                }
                
                //it checks, is there any board on east direction or not
                if(j == A[0].size()-1){
                    sum += A[i][j];
                }else{
                    sum += max(0,A[i][j]-A[i][j+1]);
                }
            }
        }
        
        return sum;