Morgan Stanley interview question

sort the list and sorting based