Morgan Stanley interview question

Sort the array using one for loop