Median order value

Median order value

Airbnb Statistics Interview Question

Airbnb reports a typical booking value each week. A handful of very expensive stays pull the average up, so the team reports the middle value instead.

Write median_order_value(values) that returns the median of a list of numbers, rounded to two decimal places. With an even count, return the mean of the two middle values.

Asked of

  • Data Analyst
  • Business Analyst
  • Product Analyst
  • Analytics Engineer
  • Data Scientist

Example 1

Input

values = [3, 1, 2]

Output

2

Example 2

Input

values = [4, 1, 3, 2]

Output

2.5

Example 3

Input

values = [5]

Output

5

Explanation

Sorted, [3, 1, 2] is [1, 2, 3] and the middle value is 2. [4, 1, 3, 2] sorts to [1, 2, 3, 4], and the two middle values 2 and 3 average to 2.5.

Submit also runs 3 hidden test cases that check edge cases.

Similar questions