Else store the indices and values at those indices in a map and finainty print them
else { Dictionary < int , int > mpp = new Dictionary < int , int > ( ) ; mpp . Clear ( ) ; int j = 1 ; List < int > value_at_index = new List < int > ( ) ; foreach ( int x1 in ans ) { mpp . Add ( x1 , j ) ; ++ j ; } foreach ( int x2 in anss ) { value_at_index . Add ( mpp [ x2 ] ) ; } foreach ( int x3 in value_at_index ) { Console . Write ( x3 + " ▁ " ) ; } Console . WriteLine ( ) ; } }