if stack is not empty , then pop an element from stack . If the popped element is greater than next , then a ) print the pair b ) keep popping while elements are greater and stack is not empty
while ( s . length != 0 && s [ s . length - 1 ] > arr [ i ] ) { mp [ s [ s . length - 1 ] ] = arr [ i ] ; s . pop ( ) ; }