Interview Question
Share Lesson

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

Loading...
Follow teacher
Share:

Table of Contents

Validate My Answer

  1. 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.

  2. Duplicates of the same age must all appear in the output and be grouped together.

Loading...
Follow teacher
Share:

Table of Contents

Test Results

Run your code and see results here...

/**
 * @param {number[]} ageList
 * @return {number[]}
 */
const sortByAge = (ageList) => {
  // Your solution here
}
// Upgrade for full course access
// Upgrade for full course access

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.

 
/**
 * @param {number[]} ageList
 * @return {number[]}
 */
const sortByAge = (ageList) => {
  // Your solution here
}
// Upgrade for full course access
// Upgrade for full course access