Morgan Stanley Interview Question

Sort the array using one for loop