Swap pair of arr [ i ] with arr [ i + 1 ] and recursively compute minimum swap required if this move is made .
var one = arr [ i + 1 ] ; var indextwo = i + 1 ; var indexone = index [ pairs [ arr [ i ] ] ] ; var two = arr [ index [ pairs [ arr [ i ] ] ] ] ; arr [ i + 1 ] = arr [ i + 1 ] ^ arr [ indexone ] ^ ( arr [ indexone ] = arr [ i + 1 ] ) ; updateindex ( index , one , indexone , two , indextwo ) ; var a = minSwapsUtil ( arr , pairs , index , i + 2 , n ) ;