Solves the insertion sort problem from hacker rank