If stack becomes empty , then no element is greater on left side . Else top of stack is previous greater .
if ( s . length == 0 ) document . write ( " " ) ; else document . write ( s [ s . length - 1 ] + " " ) ; s . push ( arr [ i ] ) ; } }