For example, the original vector is (2, 4, 1, 0).
After swapping, it can be (1, 0, 2, 4) or (0, 1, 4, 2).
The second outcome is what I want because every absolute value of the difference between the original values and the new values are equal to or more than 2, say|2-0|=2, |4-1|>2, |1-4|>2, |0-2|=2.
However, the first outcome is not what I want because for example |2-1|<2.
How to decide whether the original vector can be swapped to a new vector where every absolute value of the difference between the original values and the new values are equal to or more than 2?
Any suggestions? Many thanks.
First, put your entries in increasing order, $a_1\le a_2\le\cdots\le a_{2n}$. Then in your original vector swap $a_i$ with $a_{n+i}$ for each $i$. If that doesn't work, nothing will.
In your example, you go $0,1,2,4$, then swap $0$ with $2$, and $1$ with $4$ (as you did).
You have to fudge this a little, if your vector has an odd number of entries.