If you log out the array swapped you see the following modification
nums [ 4, 2, 1, 2 ]
nums [ 2, 2, 1, 4 ]
nums [ 2, 3, 2, 1 ]
nums [ 3, 2, 2, 1 ]
nums [ 2, 2, 3, 1 ]
The array is perminantly changed, added a 3 and deleted the 4 somehow. I think what we need to do is add a check that "skips"a swap if the swap location is already correct.
Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Find all Missing Numbers (easy) - Grokking the Coding Interview: Patterns for Coding Questions