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.
defsurfaceArea(A):# Write your code heref_b=0#frontbackt_b=0#topbottoml_r=0#leftright#top and bottom surface areat_b=H*W*2#Front and Back surface areaifH==1:forjinrange(W):f_b+=A[0][j]*2else:foriinrange(H):forjinrange(W):ifi==H-1:f_b+=A[i][j]f_b+=(abs(A[i][j]-A[i-1][j]))elifi!=0:f_b+=(abs(A[i][j]-A[i-1][j]))else:f_b+=A[i][j]#leftandrightsurfaceareaifW==1:foriinrange(H):l_r+=A[i][0]*2else:forjinrange(W):foriinrange(H):ifj==W-1:l_r+=A[i][j]l_r+=(abs(A[i][j]-A[i][j-1]))elifj!=0:l_r+=(abs(A[i][j]-A[i][j-1]))else:l_r+=A[i][j]returnf_b+l_r+t_b
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 →
python