Else store the indices and values at those indices in a map and finainty print them
else { unordered_map < int , int > mpp ; mpp . clear ( ) ; int j = 1 ; vector < int > value_at_index ; for ( auto & x : ans ) { mpp [ x ] = j ; ++ j ; } for ( auto & x : anss ) { value_at_index . push_back ( mpp [ x ] ) ; } for ( auto & x : value_at_index ) { cout << x << " ▁ " ; } cout << endl ; } }