Course launching November 17, 2020
Follow me on YouTube for free coding interview videos.
Users who sign up for the email list will receive an exclusive 75% discount at launch.
You started a new job and received your first assignment. You work for a huge ecommerce company that receives millions of orders per day, and they have asked you to create a sorted list of ages associated with each order.
Given a list of ages, write a function
sortByAge that returns a sorted list of all the ages in ascending order.
You can reasonably assume the range of ages is 0 to 100.
sortByAge([33, 25, 99, 33, 50, 42]); // [25, 33, 33, 42, 50, 99]
Validate My Answer
A brute force solution would just be to use our native sorting function for O(n log n) time. You can actually do this in O(n) time. Think through constraints on this question that make that possible.
Duplicates of the same age must all appear and be grouped together.