← PayPal Interview Insights

PayPal·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Did a technical screen for a Data Scientist role at PayPal and got a coding question on computing variance from scratch in Python. Pretty focused session, no fluff.

Questions Asked (1)

Q1

Given a Python list of numbers, implement a function to compute its variance without using numpy or pandas. Be prepared to discuss population vs sample variance, edge cases, and complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I jumped straight into the sample variance formula without asking which type they wanted, and the interviewer had to stop me to clarify.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the definition of variance and whether the interviewer wants population or sample variance. Then implement a clean, efficient function that handles edge cases like empty lists and single-element lists, and discuss the time and space complexity. Be prepared to explain the difference between population and sample variance and when to use each.

Pro tip: Mention that for numerical stability, you can use a two-pass algorithm (compute mean first, then sum of squared deviations) or Welford's online algorithm for a single pass, especially for large datasets. This shows awareness of floating-point precision issues.

1. Clarify requirements

Ask whether to compute population variance (divide by N) or sample variance (divide by N-1). Confirm input assumptions: list of numbers, may be empty or have one element.

2. Choose algorithm

Decide between two-pass (compute mean, then sum of squared deviations) or one-pass (Welford's algorithm). Two-pass is simpler and usually sufficient; one-pass is more numerically stable and efficient for streaming data.

3. Implement function

Write the function in Python, handling edge cases: empty list (raise ValueError or return None), single element (population variance 0, sample variance undefined). Use clear variable names and comments.

4. Analyze complexity

State time complexity O(n) and space complexity O(1) for both algorithms. Mention that two-pass requires two iterations but still O(n).

5. Discuss trade-offs and edge cases

Explain when to use population vs sample variance, and the impact of numerical stability. Mention that for very large datasets, Welford's algorithm avoids catastrophic cancellation.

Key Points to Mention

  • Population variance divides by N, sample variance divides by N-1 (Bessel's correction).
  • Edge cases: empty list, single element, non-numeric inputs.
  • Time complexity O(n), space complexity O(1).
  • Numerical stability: two-pass vs one-pass (Welford's algorithm).
  • Use cases: population variance for entire dataset, sample variance for estimating from a sample.
  • Avoid using numpy/pandas as instructed; implement from scratch.

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