← PayPal Interview Insights

PayPal·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Interviewed for a Data Scientist role at PayPal and got a pure coding question about implementing variance from scratch in Python. No libraries allowed, which was a bit of a curveball for a DS interview rather than a pure SWE one.

Questions Asked (1)

Q1

Write a Python function to compute the variance of a list of numbers without using any external libraries like NumPy or pandas. Discuss your assumptions around population vs. sample variance, edge cases like empty or single-element lists, and the time and space complexity of your solution.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Spent the first minute just asking clarifying questions, which I think saved me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the variance definition (population vs. sample) and edge cases, then implement a two-pass algorithm that computes the mean first and then the sum of squared deviations. Discuss time and space complexity, and optionally mention a one-pass alternative like Welford's algorithm for numerical stability.

Pro tip: Mention that for large datasets, a one-pass algorithm like Welford's method avoids catastrophic cancellation and is more memory-efficient, showing awareness of numerical stability and scalability—key for production data science at PayPal.

1. Clarify requirements and assumptions

Ask whether the variance should be population or sample, and confirm handling of edge cases like empty or single-element lists. State your assumptions explicitly before coding.

2. Design the algorithm

Choose a two-pass approach: first compute the mean, then sum squared differences from the mean. For sample variance, divide by n-1; for population, divide by n.

3. Implement the function

Write clean Python code with appropriate error handling for edge cases (e.g., return None or raise ValueError for empty list; for single element, sample variance is undefined).

4. Analyze complexity

Explain that the two-pass algorithm runs in O(n) time and O(1) extra space (beyond the input list). Mention that a one-pass algorithm like Welford's is also O(n) time and O(1) space but more numerically stable.

5. Discuss trade-offs and extensions

Compare two-pass vs. one-pass (Welford's) in terms of numerical stability and simplicity. Mention that for streaming data, one-pass is preferred.

Key Points to Mention

  • Population variance divides by n, sample variance divides by n-1 (Bessel's correction).
  • Edge cases: empty list (undefined), single element (population variance 0, sample variance undefined).
  • Time complexity: O(n) for both two-pass and one-pass algorithms.
  • Space complexity: O(1) extra space for both, aside from input storage.
  • Numerical stability: two-pass can suffer from catastrophic cancellation; Welford's algorithm is more stable.
  • Implementation details: use float division, handle potential division by zero, and consider using math.fsum for accurate summation.

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