Now pop the remaining bars from stack and calculate area with every popped bar as the smallest bar
while ( len ( s ) != 0 ) : NEW_LINE INDENT tp = s [ - 1 ] NEW_LINE s . pop ( ) NEW_LINE if len ( s ) == 0 : NEW_LINE INDENT area_with_top = hist [ tp ] * i NEW_LINE DEDENT else : NEW_LINE INDENT area_with_top = hist [ tp ] * ( i - s [ - 1 ] - 1 ) NEW_LINE DEDENT if ( max_area < area_with_top ) : NEW_LINE INDENT max_area = area_with_top NEW_LINE DEDENT DEDENT return max_area NEW_LINE