Outliers by z-score

Outliers by z-score

Stripe Statistics Interview Question

Stripe flags payment amounts that sit far from the rest of a merchant’s traffic, measuring the distance in standard deviations so the rule works whatever the merchant’s usual size.

Write outliers_by_z_score(values, threshold) that returns the values whose distance from the mean, divided by the population standard deviation, is greater than the threshold. Keep them in the order they arrived, and return an empty list when every value is identical.

Asked of

  • Data Analyst
  • Analytics Engineer
  • Data Scientist
  • ML Engineer

Example 1

Input

values = [1, 2, 3, 4, 100], threshold = 1.5

Output

[100]

Example 2

Input

values = [5, 5, 5, 5], threshold = 1

Output

[]

Example 3

Input

values = [1, 2, 3, 4, 5], threshold = 3

Output

[]

Explanation

For [1, 2, 3, 4, 100] the mean is 22 and the standard deviation is about 39. Only 100 is more than 1.5 standard deviations away, so it is the only value returned.

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

Similar questions