If stack becomes empty , then no element is greater on left side . Else top of stack is previous greater .
if len ( s ) == 0 : NEW_LINE INDENT print ( " - 1 , ▁ " , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( s [ - 1 ] , " , ▁ " , end = " " ) NEW_LINE DEDENT s . append ( arr [ i ] ) NEW_LINE