← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Google data scientist interview that went deep into statistical sampling theory, way deeper than I expected for a DS role. The whole session was basically one long question about truncated normals and I was not fully prepared for the numerical precision angle.

Questions Asked (5)

Q1

Define the truncated normal distribution for Z given a < Z < b where Z is standard normal. Write out the normalized pdf and cdf.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This part was fine, I knew the forms.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the truncated normal distribution for a standard normal Z restricted to (a, b). Then derive the normalized PDF by dividing the standard normal PDF by the probability mass in the interval, and express the CDF as a difference of standard normal CDFs divided by that same probability. Emphasize the role of the normalizing constant and the connection to the standard normal.

Pro tip: Mention that the truncated normal is often used in survival analysis and econometrics, and that the normalizing constant ensures the density integrates to 1. Also, note that if a = -∞ or b = ∞, it reduces to a one-sided truncation.

1. Define the truncation

State that Z is standard normal (mean 0, variance 1) and we condition on a < Z < b. The truncation interval is (a, b) with a < b.

2. Write the standard normal PDF and CDF

Recall the standard normal PDF φ(z) = (1/√(2π)) e^{-z²/2} and CDF Φ(z). These are the building blocks for the truncated distribution.

3. Compute the normalizing constant

The probability that Z falls in (a, b) is P(a < Z < b) = Φ(b) - Φ(a). This constant ensures the truncated PDF integrates to 1.

4. Write the truncated PDF

The PDF is f_Z(z | a < Z < b) = φ(z) / (Φ(b) - Φ(a)) for a < z < b, and 0 otherwise.

5. Write the truncated CDF

The CDF is F_Z(z | a < Z < b) = (Φ(z) - Φ(a)) / (Φ(b) - Φ(a)) for a ≤ z ≤ b, with F(z) = 0 for z < a and F(z) = 1 for z > b.

Key Points to Mention

  • The standard normal PDF φ(z) and CDF Φ(z).
  • The normalizing constant P(a < Z < b) = Φ(b) - Φ(a).
  • The truncated PDF is zero outside the interval (a, b).
  • The truncated CDF is a rescaled version of Φ(z) that goes from 0 to 1 over the interval.
  • Special cases: one-sided truncation when a = -∞ or b = ∞.
  • Applications in statistics and machine learning, such as truncated regression or Tobit models.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Design efficient samplers for three specific truncated normal cases: (i) lower tail cutoff at 1 with no upper bound, (ii) a very narrow interval from 4 to 4.05, and (iii) a lower tail cutoff at 4 with no upper bound. For each case, compare inverse-CDF sampling against naive rejection sampling from a standard normal.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where things got interesting and also where I started sweating.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

For each truncated normal case, analyze the acceptance probability of naive rejection sampling from a standard normal and compare it to the efficiency and exactness of inverse-CDF sampling. Discuss the trade-offs in terms of computational cost, implementation complexity, and numerical stability, especially for extreme truncation regions. Conclude with a recommendation for each case based on the analysis.

Pro tip: Quantify the acceptance rates for the rejection sampler (e.g., for case (i) it's about 15.9%, for (ii) it's ~0.0001%, and for (iii) it's ~0.00003%) to concretely demonstrate why rejection sampling is impractical for the latter two. Also, mention that inverse-CDF sampling requires evaluating the normal CDF and its inverse, which are readily available in standard libraries but may have numerical issues in extreme tails.

1. Understand the problem and define truncation regions

Restate the three cases: (i) X ~ N(0,1) truncated to [1, ∞), (ii) truncated to [4, 4.05], (iii) truncated to [4, ∞). Clarify that the goal is to sample from these truncated distributions efficiently.

2. Analyze naive rejection sampling

For each case, compute the acceptance probability (the probability mass of the truncation region under the standard normal). Discuss that the number of trials needed follows a geometric distribution with mean 1/p, leading to high computational cost when p is very small.

3. Analyze inverse-CDF sampling

Explain that inverse-CDF sampling involves generating U ~ Uniform(0,1) and setting X = Φ^{-1}(Φ(a) + U*(Φ(b)-Φ(a))). Discuss its exactness and constant time per sample, but note potential numerical challenges when Φ(a) and Φ(b) are extremely close to 0 or 1.

4. Compare and recommend for each case

For case (i), both methods are feasible; rejection sampling has ~15.9% acceptance, but inverse-CDF is still more efficient. For case (ii), rejection sampling is extremely inefficient (acceptance ~0.0001%), so inverse-CDF is preferred despite numerical precision issues. For case (iii), rejection sampling is even worse (~0.00003%), so inverse-CDF is necessary, but consider using specialized algorithms for extreme tails.

5. Discuss practical considerations and alternatives

Mention that for extreme truncation, inverse-CDF may suffer from loss of precision; alternatives include using a shifted exponential approximation or specialized samplers like the one by Robert (1995). Also, note that for case (ii), the interval is so narrow that the distribution is nearly uniform, so one could approximate by sampling uniformly and adjusting.

Key Points to Mention

  • Acceptance probability for rejection sampling: p = Φ(b) - Φ(a) for truncation to [a,b].
  • Expected number of trials for rejection sampling is 1/p, which can be huge for extreme truncation.
  • Inverse-CDF sampling is exact and O(1) per sample, but requires accurate evaluation of Φ and Φ^{-1}.
  • Numerical issues: Φ(4) is about 0.9999683, so Φ(4.05)-Φ(4) is about 3e-5, and computing Φ^{-1} near 1 can lose precision.
  • For case (ii), the truncated normal is nearly uniform over [4,4.05], so a uniform approximation might suffice.
  • For case (iii), the truncated normal is essentially a shifted exponential tail; one can use the fact that for large x, the normal density is proportional to exp(-x^2/2), which behaves like an exponential with rate x.
  • Trade-offs: rejection sampling is simple but inefficient for rare events; inverse-CDF is efficient but may require careful numerical implementation.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Propose a sampling algorithm suited for extreme tail regions, such as an exponential or half-normal proposal with acceptance-rejection. Walk through the construction and why it works better than the alternatives.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the general idea: use an exponential proposal shifted to the truncation point and find a bound on the density ratio.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by framing the problem: we need to sample from a target distribution's extreme tail where direct sampling is inefficient. Propose an acceptance-rejection algorithm with an exponential or half-normal proposal, derive the acceptance probability, and explain why it outperforms alternatives like uniform proposals or MCMC in terms of efficiency and tail accuracy.

Pro tip: Emphasize the importance of the proposal's tail behavior matching the target's—exponential or half-normal proposals have heavier tails than many targets, ensuring bounded likelihood ratios and high acceptance rates. Also, mention that for very extreme tails, you might need to use a shifted or truncated proposal to avoid underflow.

1. Define the problem and target distribution

Clearly state that we want to sample from the extreme tail of a distribution (e.g., beyond a high threshold) where direct methods are impractical. Specify the target density f(x) and the tail region of interest.

2. Choose a proposal distribution

Select an exponential or half-normal proposal g(x) that is easy to sample from and has tails at least as heavy as the target in the region of interest. Justify the choice based on tail behavior and computational simplicity.

3. Derive the acceptance-rejection algorithm

Compute the bound M such that f(x)/g(x) ≤ M for all x in the tail. The acceptance probability is f(x)/(M g(x)). Describe the steps: sample Y ~ g, sample U ~ Uniform(0,1), accept if U ≤ f(Y)/(M g(Y)).

4. Analyze efficiency and compare alternatives

Discuss the acceptance rate and computational cost. Compare with alternatives like uniform proposals (which have low acceptance in tails), importance sampling (which may have high variance), or MCMC (which may mix poorly in tails). Highlight that the exponential/half-normal proposal yields higher acceptance rates and lower variance.

5. Address practical considerations and extensions

Mention how to handle very extreme tails (e.g., using a shifted exponential or a Pareto proposal), numerical stability (log-scale computations), and potential adaptations for multivariate or heavy-tailed targets.

Key Points to Mention

  • Acceptance-rejection sampling requires a proposal distribution with heavier tails than the target to ensure a finite bound M.
  • Exponential and half-normal proposals are easy to sample from and have exponential tails, which are often heavier than the target's tail in extreme regions.
  • The acceptance probability is proportional to the ratio f(x)/g(x); a good proposal keeps this ratio close to constant, maximizing acceptance.
  • Uniform proposals are inefficient in tails because the acceptance probability decays rapidly, leading to many rejections.
  • MCMC methods can suffer from poor mixing in extreme tails, requiring long chains to explore the region.
  • For very extreme tails, consider using a proposal that matches the target's tail behavior more closely (e.g., Pareto for power-law tails) or use adaptive methods.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

How do you handle numerical stability when evaluating the normal CDF and its inverse near machine precision, especially in extreme tail regions?

Technical Trade-offsSystem Design
Author's notes

Honestly the part I was least prepared for.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging the challenges of numerical stability in extreme tails, then discuss specific techniques like using erfc for the normal CDF and rational approximations for the inverse. Emphasize the importance of avoiding catastrophic cancellation and leveraging asymptotic expansions, while also mentioning practical implementations in libraries like SciPy.

Pro tip: Mention that in production, you'd use well-tested libraries rather than implementing from scratch, but understanding the underlying algorithms helps debug edge cases and optimize performance.

1. Identify the numerical challenges

Explain why direct computation of the normal CDF and its inverse fails near machine precision, such as underflow/overflow and loss of precision in extreme tails.

2. Discuss stable algorithms for the CDF

Describe using the complementary error function (erfc) for the upper tail and erfcx for scaled versions, and how these avoid cancellation and underflow.

3. Discuss stable algorithms for the inverse CDF

Mention rational approximations (e.g., Acklam's algorithm) and Newton refinement, and how to handle extreme tail regions using asymptotic expansions.

4. Address trade-offs and practical considerations

Talk about accuracy vs. speed, and the importance of using established libraries (e.g., SciPy's ndtr, ndtri) that implement these techniques.

5. Provide examples or use cases

Give a concrete example, such as computing p-values in hypothesis testing or quantiles for risk models, where numerical stability is critical.

Key Points to Mention

  • Use of erfc and erfcx for stable CDF computation
  • Rational approximations and Newton's method for inverse CDF
  • Asymptotic expansions for extreme tails
  • Avoiding catastrophic cancellation and underflow
  • Leveraging well-tested libraries like SciPy or Boost
  • Trade-offs between accuracy, speed, and implementation complexity

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

How would you validate that your truncated normal sampler is actually correct? Describe a testing approach.

A/B Testing & ExperimentationTechnical Trade-offs
Author's notes

Back-transformed uniforms via a KS test plus moment checks.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by outlining a multi-layered validation strategy that combines theoretical checks, statistical tests, and empirical comparisons. Emphasize the importance of testing edge cases and using known properties of the truncated normal distribution. Conclude by discussing how you would integrate these tests into a continuous validation pipeline.

Pro tip: Leverage the fact that the truncated normal distribution has a known CDF and moments; use them to create precise statistical tests rather than relying solely on visual inspection. Also, consider using a reference implementation from a trusted library (e.g., scipy.stats.truncnorm) for comparison.

1. Theoretical Validation

Verify that the sampler's output matches the known theoretical properties of the truncated normal distribution, such as the mean, variance, and CDF. Use analytical formulas for these moments and compare with empirical estimates from a large sample.

2. Statistical Hypothesis Testing

Apply goodness-of-fit tests like Kolmogorov-Smirnov or Anderson-Darling to check if the sampled data follows the expected truncated normal distribution. Also, test for independence and randomness if the sampler is supposed to produce i.i.d. samples.

3. Edge Case and Boundary Testing

Test scenarios where the truncation bounds are extreme (e.g., very narrow or wide intervals, bounds far in the tails) to ensure numerical stability and correctness. Check behavior when the distribution is nearly normal or highly truncated.

4. Comparison with Reference Implementations

Compare your sampler's output with a trusted reference implementation (e.g., scipy.stats.truncnorm) using metrics like KL divergence, Wasserstein distance, or visual QQ-plots. Ensure that any differences are within acceptable tolerance.

5. Integration and Regression Testing

Incorporate these validation checks into an automated test suite that runs on every code change. Include tests for reproducibility (with fixed seeds) and performance to catch regressions.

Key Points to Mention

  • Known moments of truncated normal (mean, variance) and how to compute them analytically
  • Goodness-of-fit tests (Kolmogorov-Smirnov, Anderson-Darling, chi-squared)
  • Visual diagnostics (QQ-plots, histograms, P-P plots) and their limitations
  • Comparison with trusted libraries (scipy.stats.truncnorm) and distance metrics (KL divergence, Wasserstein)
  • Edge cases: extreme truncation, bounds at infinity, numerical stability
  • Reproducibility and automated testing (unit tests, CI/CD integration)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.