This function returns minimum number of swaps required to arrange all elements of arr [ i . . n ] become arranged
public static int minSwapsUtil ( int [ ] arr , int [ ] pairs , int [ ] index , int i , int n ) {