Update the indexes in the hashmap accordingly
h . put ( init , h . get ( temp [ i ] ) ) ; h . put ( temp [ i ] , i ) ; } } return ans ; } public void swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } }