The greedy approach: process pairs from left to right. For positions , , etc., check if a couple sits there.
If not, swap to fix it. For person at position , their partner is either (XOR flips the last bit).
If the person at is not the partner, find the partner elsewhere and swap. Each swap fixes exactly one couple.
You never need to undo a fix.
This greedy approach gives minimum swaps.