Morgan Stanley Interview Question

sort the list and sorting based