PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Uber
  • Coding & Algorithms
  • Data Scientist

Compute CDF from a PDF Function

Company: Uber

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a callable function `pdf(t)` that returns the probability density of a normal distribution at value `t`. Implement a function `cdf(x)` that returns the cumulative probability: `P(X <= x) = integral from -infinity to x of pdf(t) dt` Requirements: - You may call `pdf(t)` as often as needed. - Do not call a built-in CDF function from a statistics library. - Use a numerical method to approximate the integral. - Your implementation should handle positive and negative `x` values. - State any assumptions you make about numerical precision, integration bounds, and convergence.

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.

You are given the probability density function of the standard normal distribution: pdf(t) = exp(-t*t/2) / sqrt(2*pi). Implement a function solution(x) that returns the cumulative probability P(X <= x) by numerically approximating the integral of the PDF. Do not use math.erf, scipy, or any built-in CDF function from a statistics library. Your approach must work for both positive and negative x values. Assumptions for this problem: returning the answer rounded to 6 decimal places is sufficient; because the standard normal distribution is symmetric, you may compute the integral over [0, |x|] instead of integrating from negative infinity; and using a sufficiently fine even partition should be treated as converged for this precision.

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

  1. Use the symmetry of the standard normal distribution: Phi(0) = 0.5 and Phi(-x) = 1 - Phi(x).
  2. Simpson's rule is a good numerical integration choice for smooth functions like the normal PDF.
Last updated: May 7, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Maximize Throughput and Count Trigger Components - Uber (medium)
  • Replace Dashes With Nearest Letters - Uber (medium)
  • Find Earliest Column With One - Uber (easy)
  • Solve Wonderful Strings and Grid Queries - Uber (hard)
  • Count Islands After Land Additions - Uber (medium)