← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Google data science coding round with two numerical/statistical problems. Both questions had a math-heavy flavor and required knowing your way around distributions and loss functions, not just writing clean code.

Questions Asked (2)

Q1

Write functions to sample from a truncated normal distribution under three different constraints: x greater than 1, x between 4 and 4.05, and x greater than 4.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The first case was fine, rejection sampling works and you don't lose too many draws.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the parameters of the normal distribution (mean and standard deviation) and the truncation bounds. Then, for each constraint, choose an appropriate sampling method: inverse transform sampling for one-sided truncation, and rejection sampling or inverse transform for narrow intervals. Discuss the trade-offs between accuracy and efficiency, especially for the narrow interval [4, 4.05].

Pro tip: For the narrow interval, inverse transform sampling is more efficient than rejection sampling because the acceptance rate is extremely low. Also, mention that you can precompute the CDF values for the truncated bounds to speed up sampling.

1. Clarify parameters and constraints

Ask for the mean and standard deviation of the normal distribution. Confirm the truncation bounds: x > 1, 4 < x < 4.05, and x > 4.

2. Choose sampling method per constraint

For one-sided truncation (x > a), use inverse transform sampling: sample u ~ Uniform(Φ((a-μ)/σ), 1), then x = μ + σ Φ^{-1}(u). For two-sided truncation (a < x < b), sample u ~ Uniform(Φ((a-μ)/σ), Φ((b-μ)/σ)), then transform.

3. Implement functions

Write a function for each case. Use scipy.stats.norm for CDF and inverse CDF (ppf). For the narrow interval, ensure numerical stability by computing Φ((b-μ)/σ) - Φ((a-μ)/σ) accurately.

4. Validate and discuss trade-offs

Test the functions by generating samples and checking they fall within bounds. Compare inverse transform vs. rejection sampling: rejection is simple but inefficient for narrow intervals; inverse transform is efficient but requires CDF inversion.

Key Points to Mention

  • Inverse transform sampling using the truncated CDF
  • Rejection sampling and its low acceptance rate for narrow intervals
  • Numerical stability when computing differences of CDF values
  • Use of scipy.stats.norm.ppf and cdf
  • Trade-off between simplicity and efficiency
  • Handling of one-sided vs. two-sided truncation

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

Q2

Given an array X, find the value of theta that minimizes the sum of squared errors, then the sum of absolute errors, and finally derive what loss function would give you the 90th percentile as its solution.

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

Mean and median parts were straightforward once I remembered to just take derivatives.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by recognizing that minimizing squared error yields the mean, absolute error yields the median, and the 90th percentile arises from minimizing an asymmetric absolute loss (quantile loss). Explain each case with mathematical reasoning, then generalize to quantile regression. Connect these to practical applications like robust regression and quantile forecasting.

Pro tip: Mention that the quantile loss is also known as the pinball loss, and that it is used in quantile regression and gradient boosting (e.g., LightGBM's objective='quantile'). This shows depth and practical awareness.

1. Squared Error Minimization

Show that the sum of squared errors is minimized by the mean. Derive by setting the derivative to zero: d/dθ Σ(x_i - θ)^2 = -2 Σ(x_i - θ) = 0 => θ = mean.

2. Absolute Error Minimization

Show that the sum of absolute errors is minimized by the median. Explain that the derivative is the sign of (θ - x_i), and the subgradient condition leads to θ being any median.

3. Generalize to Quantiles

Introduce the asymmetric absolute loss: L_τ(θ) = Σ [τ * max(x_i - θ, 0) + (1-τ) * max(θ - x_i, 0)]. Explain that minimizing this yields the τ-th quantile.

4. Derive 90th Percentile

Set τ = 0.9. Show that the minimizer is the 90th percentile by considering the subgradient: the proportion of points below θ should be 0.9.

5. Connect to Applications

Mention that this loss is used in quantile regression, and that it provides a way to estimate conditional quantiles. Highlight its robustness compared to squared error.

Key Points to Mention

  • Mean minimizes squared error; median minimizes absolute error.
  • Quantile loss (pinball loss) is asymmetric absolute loss with weight τ.
  • The τ-th quantile minimizes the expected quantile loss.
  • For τ=0.9, the solution is the 90th percentile.
  • Quantile regression estimates conditional quantiles and is robust to outliers.
  • The loss can be written as τ * max(x-θ,0) + (1-τ) * max(θ-x,0).

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