We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intsurfaceArea(vector<vector<int>>A){inttop_downface=A.size()*A[0].size(),frontface=0,leftface=0,rightface=0,rearface=0;vector<int>previous_row_height_t2b(A[0].size(),0),previous_row_height_b2t(A[0].size(),0);for(inti=0;i<A.size();i++){intprevious_row_height_l2r=0,previous_row_height_r2l=0,k,l=A.size()-i-1;//backward iterator over rowsfor(intj=0;j<A[0].size();j++){k=A[i].size()-j-1;//backward iterator over colsfrontface+=(previous_row_height_t2b[j]<A[i][j])?A[i][j]-previous_row_height_t2b[j]:0;rearface+=(previous_row_height_b2t[j]<A[l][j])?A[l][j]-previous_row_height_b2t[j]:0;leftface+=(previous_row_height_l2r<A[i][j])?A[i][j]-previous_row_height_l2r:0;rightface+=(previous_row_height_r2l<A[i][k])?A[i][k]-previous_row_height_r2l:0;previous_row_height_l2r=A[i][j];previous_row_height_r2l=A[i][k];}previous_row_height_t2b=A[i];previous_row_height_b2t=A[l];}return2*top_downface+rearface+frontface+leftface+rightface;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
3D Surface Area
You are viewing a single comment's thread. Return to all comments →
C++20