
The 95th percentile
mediumThe 95th percentile
Datadog Statistics Interview Question
Datadog reports the slow end of a response time distribution rather than the average, because an average hides the requests that make users leave.
Write p95_response_time(times) that returns the 95th percentile by nearest rank: sort the values, then return the one at position ceil(0.95 × n), counting from 1.
Asked of
- Data Analyst
- Analytics Engineer
- Data Engineer
- Data Scientist
- ML Engineer
- MLOps Engineer
Example 1
Input
times = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Output
19
Example 2
Input
times = [5, 1, 3]
Output
5
Example 3
Input
times = [42]
Output
42
Explanation
With 20 values, 0.95 × 20 is 19, so the answer is the 19th smallest. With 3 values, 0.95 × 3 is 2.85, which rounds up to 3, so the answer is the largest.
Submit also runs 2 hidden test cases that check edge cases.
- Calculations
Similar questions
Company
Datadog
Difficulty
medium
Topic
Statistics
Language
Python
Your code
Loading Python in the background. You can start writing.