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.
functionsurfaceArea(A){if(A.length===1&&A[0]===1)return6;letsurface=0;for(letrow=0;row<A.length;row++){constcurrentRow=A[row];for(letcol=0;col<currentRow.length;col++){constheight=currentRow[col];// Add top and bottom surfacessurface+=2;// Add side surfacesconstneighbors=[row>0?A[row-1][col]:0,// Frontrow<A.length-1?A[row+1][col]:0,// Backcol>0?currentRow[col-1]:0,// Leftcol<currentRow.length-1?currentRow[col+1]:0,// Right];for(constneighborofneighbors){surface+=Math.max(0,height-neighbor);}}}returnsurface;}
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 →
JS: