Fewest swaps to sort a permutation
The array [4, 7, 1, 9, 3, 10, 2, 8, 5, 6] holds a permutation of . A move swaps the contents of any two positions (not necessarily adjacent). What is the minimum number of moves needed to sort it into [1, 2, ..., 10]?
Show hints (2)+
- Follow position value position ... until you return; that is a cycle.
- How many swaps does a cycle of length need?
Answer
Reveal answer →Final answer
6
Create a free account to see the full worked solution and track your progress.
Interview format: Prop Trading