solution to swapPairs