Minimum Number of Swaps to Sort an Array of consecutive integers
Well, the title speaks for itself!
Try it yourself on HackerRank
Apparently this is quite a common interview question (asked at Google Phone Screen). Sadly, I couldn’t find some good visualizations to understand the underlying logic behind the solving this problem. So, I couldn’t help but write one for myself.
In this post we explore the minimum swaps required to sort, and array/list of consecutive integers, note that the case of non-consecutive integers will be slightly…