Given 2 sequences a and b what is best way to rearrange the b array so that no two elements at same index are equal.
a = 1 1 1 2 2 3
b = 1 1 1 2 2 3
we can rearrange b to make 2 2 3 1 1 1 and hence no two elements at same index are same.
It can be possible that there is no rearrangement as well.
Assume 1st sequence is sorted
This is the matching (or marriage) problem, where „boy“ $i$ and „girl“ $j$ can match iff $a_i\ne b_j$.