PracHub
QuestionsLearningGuidesInterview Prep
|Home/Data Manipulation (SQL/Python)/Waymo

Implement a Safe Average Function in Python

Last updated: Jul 28, 2026

Quick Overview

Implement a Python average function that returns zero for an empty list and explain its time and space complexity. Clarify numeric types, missing values, NaN behavior, streaming alternatives, precision concerns, and the tests needed for a reliable data utility.

  • medium
  • Waymo
  • Data Manipulation (SQL/Python)
  • Data Scientist

Implement a Safe Average Function in Python

Company: Waymo

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Take-home Project

Write a Python function `average(table)` that returns the arithmetic mean of a list of numbers and returns `0` when the list is empty. Explain the function's behavior, complexity, and any input assumptions you would clarify before using it in a data pipeline. ### Constraints & Assumptions - The required empty-list result is exactly `0`. - A direct implementation with Python's built-in numeric operations is sufficient. - Do not silently invent missing-value semantics; explain how `None` or `NaN` would be handled if they can appear. ### Clarifying Questions to Ask - Are integers and floating-point values both valid? - Can the input contain `None`, `NaN`, nonnumeric values, or an iterator rather than a list? - Should the function return an integer or floating-point zero for an empty input? - Is numerical overflow or precision important for the expected data size? ### What a Strong Answer Covers - A correct empty-input branch and correct arithmetic mean for nonempty input. - Time complexity proportional to the number of values and constant auxiliary space for a list input. - Explicit behavior for invalid or missing values rather than accidental coercion. - Awareness that production data work may use library functions with different missing-value rules. ### Follow-up Questions 1. How would you adapt the function to ignore `None` values? 2. How would you compute the mean of a stream that cannot be stored in memory? 3. What happens when the input contains `float('nan')`? 4. How would you test this function?

Quick Answer: Implement a Python average function that returns zero for an empty list and explain its time and space complexity. Clarify numeric types, missing values, NaN behavior, streaming alternatives, precision concerns, and the tests needed for a reliable data utility.

Related Interview Questions

  • Top 5 Most Efficient Vehicle Models - Waymo (medium)
  • Analyze User Ride Activity with SQL - Waymo (medium)
  • Compute Ride Metrics in SQL - Waymo (medium)
  • Merge overlapping intervals per group in pandas - Waymo (easy)
|Home/Data Manipulation (SQL/Python)/Waymo

Implement a Safe Average Function in Python

Waymo logo
Waymo
Mar 14, 2026, 12:00 AM
mediumData ScientistTake-home ProjectData Manipulation (SQL/Python)
3
0

Write a Python function average(table) that returns the arithmetic mean of a list of numbers and returns 0 when the list is empty. Explain the function's behavior, complexity, and any input assumptions you would clarify before using it in a data pipeline.

Constraints & Assumptions

  • The required empty-list result is exactly 0 .
  • A direct implementation with Python's built-in numeric operations is sufficient.
  • Do not silently invent missing-value semantics; explain how None or NaN would be handled if they can appear.

Clarifying Questions to Ask Guidance

  • Are integers and floating-point values both valid?
  • Can the input contain None , NaN , nonnumeric values, or an iterator rather than a list?
  • Should the function return an integer or floating-point zero for an empty input?
  • Is numerical overflow or precision important for the expected data size?

What a Strong Answer Covers Guidance

  • A correct empty-input branch and correct arithmetic mean for nonempty input.
  • Time complexity proportional to the number of values and constant auxiliary space for a list input.
  • Explicit behavior for invalid or missing values rather than accidental coercion.
  • Awareness that production data work may use library functions with different missing-value rules.

Follow-up Questions Guidance

  1. How would you adapt the function to ignore None values?
  2. How would you compute the mean of a stream that cannot be stored in memory?
  3. What happens when the input contains float('nan') ?
  4. How would you test this function?
Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More Waymo•More Data Scientist•Waymo Data Scientist•Waymo Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.