PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/PayPal

Compute variance of a list in Python

Last updated: Jun 26, 2026

Quick Overview

This question evaluates understanding of statistical measures and numeric computation, focusing on implementing variance calculations (population vs sample) and considerations for numerical stability.

  • easy
  • PayPal
  • Coding & Algorithms
  • Data Scientist

Compute variance of a list in Python

Company: PayPal

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Task Given a Python list of numbers (ints/floats), write code to compute its **variance**. ### Requirements - Input: `nums: list[float]` (length \(n\ge 1\)) - Clarify whether you are computing: - **Population variance**: \(\sigma^2 = \frac{1}{n}\sum_{i=1}^n (x_i-\bar{x})^2\), or - **Sample variance**: \(s^2 = \frac{1}{n-1}\sum_{i=1}^n (x_i-\bar{x})^2\) (requires \(n\ge 2\)) - Avoid using `numpy`/`pandas` unless explicitly allowed. - State time and space complexity. ### Follow-ups (optional) - Implement a numerically stable one-pass version. - Handle edge cases (empty list, single element, very large numbers).

Quick Answer: This question evaluates understanding of statistical measures and numeric computation, focusing on implementing variance calculations (population vs sample) and considerations for numerical stability.

Related Interview Questions

  • Minimize a String Using Allowed Swaps - PayPal (medium)
  • Explain list vs tuple in Python - PayPal (easy)
  • Solve common search/parse/graph frequency tasks - PayPal (medium)
  • Explain differences between Python list and tuple - PayPal (hard)
  • Compute Variance from a Python List - PayPal (hard)
PayPal logo
PayPal
Feb 15, 2026, 8:31 PM
Data Scientist
Technical Screen
Coding & Algorithms
9
0
Practice Read

Task

Given a Python list of numbers (ints/floats), write code to compute its variance.

Requirements

  • Input: nums: list[float] (length n≥1n\ge 1n≥1 )
  • Clarify whether you are computing:
    • Population variance : σ2=1n∑i=1n(xi−xˉ)2\sigma^2 = \frac{1}{n}\sum_{i=1}^n (x_i-\bar{x})^2σ2=n1​∑i=1n​(xi​−xˉ)2 , or
    • Sample variance : s2=1n−1∑i=1n(xi−xˉ)2s^2 = \frac{1}{n-1}\sum_{i=1}^n (x_i-\bar{x})^2s2=n−11​∑i=1n​(xi​−xˉ)2 (requires n≥2n\ge 2n≥2 )
  • Avoid using numpy / pandas unless explicitly allowed.
  • State time and space complexity.

Follow-ups (optional)

  • Implement a numerically stable one-pass version.
  • Handle edge cases (empty list, single element, very large numbers).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More PayPal•More Data Scientist•PayPal Data Scientist•PayPal Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.