pop and swap
pair < int , int > pop = stack . top ( ) ; stack . pop ( ) ; int index = pop . first , val = pop . second ; arr [ index ] = arr [ i ] ; arr [ i ] = val ; } else stack . push ( { i , arr [ i ] } ) ; } else stack . push ( { i , arr [ i ] } ) ; }