Minimum Number of Swaps to Sort an Array of consecutive integers

Abrar Shariar
Console.log()
Published in
2 min readMar 29, 2020

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…

Abrar Shariar
Console.log()

Techie | Engineer | Coder