Age Sort
You started a new job and received your first assignment. You work for a huge e-commerce 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.
Breakdown
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 in the output and be grouped together.
Age Sort
You started a new job and received your first assignment. You work for a huge e-commerce 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.