Calculate total wall area of houses painted | Function to find the total area of walls painted in N row - houses ; Stores total area of N row - houses that needs to be painted ; Traverse the array of wall heights ; Update total area painted ; Update total ; Traverse all the houses and print the shared walls ; Update total ; Print total area needs to paint ; Driver Code ; Given N , W & L ; Given heights of houses ; Function Call
def areaToPaint ( N , W , L , Heights ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT total += 2 * Heights [ i ] * W NEW_LINE DEDENT total += L * ( Heights [ 0 ] + Heights [ N - 1 ] ) NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT total += L * abs ( Heights [ i ] - Heights [ i - 1 ] ) NEW_LINE DEDENT print ( total ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 7 NEW_LINE W = 1 NEW_LINE L = 1 NEW_LINE Heights = [ 4 , 3 , 1 , 2 , 3 , 4 , 2 ] NEW_LINE areaToPaint ( N , W , L , Heights ) NEW_LINE DEDENT