Compute CDF from a PDF Function
Company: Uber
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's skills in numerical integration, applied numerical methods, and probability/statistics by requiring construction of a cumulative distribution function from a provided PDF.
Constraints
- -8.0 <= x <= 8.0
- Do not use math.erf or any statistics-library CDF
- Your answer should be accurate to within 1e-6 after rounding
Examples
Input: 0.0
Expected Output: 0.5
Explanation: By symmetry, exactly half of the probability mass lies at or below 0.
Input: 1.0
Expected Output: 0.841345
Explanation: The standard normal CDF at x = 1 is approximately 0.841345.
Input: -1.0
Expected Output: 0.158655
Explanation: Using symmetry, Phi(-1) = 1 - Phi(1) = 1 - 0.841345 = 0.158655.
Input: 1.96
Expected Output: 0.975002
Explanation: A z-score of 1.96 corresponds to a cumulative probability of about 0.975002.
Input: -3.0
Expected Output: 0.00135
Explanation: The left-tail probability at x = -3 is very small, approximately 0.00135 after rounding.
Hints
- Use the symmetry of the standard normal distribution: Phi(0) = 0.5 and Phi(-x) = 1 - Phi(x).
- Simpson's rule is a good numerical integration choice for smooth functions like the normal PDF.