← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Tough technical screen for a Data Scientist role at Google. The whole thing was basically a statistics and optimization deep dive, starting from first principles and pushing into generalization territory I hadn't fully prepared for.

Questions Asked (3)

Q1

Given an array of real numbers, derive the value that minimizes the sum of squared deviations. Show your work by setting the derivative to zero rather than just stating the answer.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew the answer is the mean but they wanted the actual derivation, not just the punchline.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Define the objective function as the sum of squared deviations from an unknown value, then differentiate with respect to that value and set the derivative to zero. Solve the resulting equation to show that the minimizing value is the arithmetic mean of the array.

Pro tip: Explicitly state that the second derivative is positive (2n), confirming the critical point is a minimum, and connect this to the mean being the least-squares estimator, which is fundamental in regression and ML loss functions.

1. Define the objective function

Let the array be x₁, x₂, ..., xₙ and the unknown value be c. Define f(c) = Σᵢ (xᵢ - c)² as the sum of squared deviations.

2. Differentiate with respect to c

Compute f'(c) = Σᵢ 2(xᵢ - c)(-1) = -2 Σᵢ (xᵢ - c) = -2(Σᵢ xᵢ - n c).

3. Set derivative to zero and solve

Set f'(c) = 0: -2(Σᵢ xᵢ - n c) = 0 ⇒ Σᵢ xᵢ = n c ⇒ c = (1/n) Σᵢ xᵢ, which is the arithmetic mean.

4. Confirm it's a minimum

Compute the second derivative f''(c) = 2n > 0, so the critical point is a minimum. Thus the mean minimizes the sum of squared deviations.

Key Points to Mention

  • The objective function is convex because it's a sum of squares, ensuring a unique global minimum.
  • The derivative of (xᵢ - c)² with respect to c is -2(xᵢ - c).
  • Setting the derivative to zero yields Σ(xᵢ - c) = 0, meaning the sum of deviations from the mean is zero.
  • The solution c = (1/n)Σxᵢ is the arithmetic mean.
  • The second derivative is 2n, which is positive, confirming a minimum.
  • This result underpins least-squares estimation and is used in linear regression and many ML algorithms.

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

Q2

Derive the value that minimizes the sum of absolute deviations, using subgradients since the absolute value isn't differentiable everywhere. Then describe an algorithm to compute it efficiently.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I slowed down.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, set up the objective function as the sum of absolute deviations and use subgradients to find the condition for optimality, showing that any median minimizes it. Then, describe an efficient algorithm such as quickselect or the median-of-medians to compute the median in linear time, or mention sorting if simplicity is preferred.

Pro tip: Emphasize that the median is robust to outliers and that the subgradient approach generalizes to other quantiles, which is valuable in many data science applications.

1. Define the objective

Let f(θ) = Σ |x_i - θ|. Explain that we want to find θ that minimizes this sum.

2. Compute subgradients

For each term, the subgradient is sign(x_i - θ) (with the convention sign(0) ∈ [-1,1]). The subgradient of the sum is the sum of these signs.

3. Set optimality condition

For θ to be a minimizer, 0 must be in the subgradient. This means the number of points less than θ is ≤ n/2 and the number greater than θ is ≤ n/2, which holds exactly when θ is a median.

4. Describe efficient algorithm

Use a linear-time selection algorithm (e.g., quickselect or median-of-medians) to find the median. Alternatively, sort the data in O(n log n) and pick the middle element.

5. Discuss trade-offs

Compare O(n) selection vs O(n log n) sorting; mention that for large n, selection is preferred. Also note that the median is robust to outliers.

Key Points to Mention

  • Subgradient of |x| is sign(x) with 0 ∈ ∂|0|
  • Optimality condition: 0 ∈ ∂f(θ) implies θ is a median
  • Median minimizes sum of absolute deviations
  • Linear-time selection algorithms (quickselect, median-of-medians)
  • Sorting approach O(n log n) vs selection O(n)
  • Robustness to outliers compared to mean

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

Q3

Generalize the absolute loss minimization to compute an arbitrary percentile, specifically the 90th. Define the tilted loss function, characterize the minimizer, and discuss how to handle ties and robustness to outliers.

Technical Trade-offsProduct Analytics & Metrics
Author's notes

Did not see this coming.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by recalling that absolute loss minimization yields the median, then generalize to the 90th percentile using the tilted (pinball) loss. Define the loss, show that its minimizer is the 90th percentile, and discuss practical issues like ties and robustness.

Pro tip: Emphasize that the tilted loss is the standard approach for quantile regression and mention that it is convex but not strictly convex, leading to potential non-unique minimizers. Also, highlight that quantiles are more robust to outliers than the mean but less than the median.

1. Review absolute loss and median

Recall that minimizing the absolute loss E|Y - c| yields the median of the distribution. This sets the stage for generalization.

2. Define tilted loss for quantiles

Introduce the tilted loss (also called pinball loss) for quantile τ: L_τ(y, c) = (y - c)(τ - 1_{y < c}). Explain that it asymmetrically penalizes over- and under-prediction.

3. Characterize the minimizer

Show that the minimizer of E[L_τ(Y, c)] is the τ-th quantile of Y. For τ=0.9, it's the 90th percentile. Provide intuition: the loss balances the probabilities of over- and under-prediction.

4. Discuss ties and non-uniqueness

Explain that if the distribution has a flat region or point mass at the quantile, the minimizer may not be unique. Any value in the interval of quantiles is a minimizer.

5. Address robustness to outliers

Compare to mean (squared loss) and median (absolute loss). The 90th percentile is robust to outliers on the lower end but can be influenced by extreme upper outliers, though less than the mean.

Key Points to Mention

  • Tilted loss formula: L_τ(y, c) = (y - c)(τ - 1_{y < c})
  • Minimizer of expected tilted loss is the τ-th quantile
  • For τ=0.9, the minimizer is the 90th percentile
  • Non-uniqueness due to ties or flat regions in the distribution
  • Robustness: quantiles are more robust than mean but less than median
  • Connection to quantile regression and its use in practice

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