Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs

Back to Questions

1. Mean

easy
GoogleGoogle
entry

Given an array of numbers nums, compute the arithmetic mean (average) using NumPy.

Return the mean rounded to 2 decimal places.

Input Signature
ArgumentType
numslist
Output Signature
Return NameType
valuefloat

Constraints

  • 1≤n≤1051 \le n \le 10^5 where nn is the length of the list

  • List elements are numeric (e.g., int or float)

  • Must raise ValueError if the input list is empty

  • Must not use external libraries (pure Python only)

Hint 1

Maintain a running sum and a count while iterating through the list.

Hint 2

Avoid dividing by len(nums) if you want a single-pass solution that also validates elements as you go.

Hint 3

Use Python’s built-in round(value, 2) to enforce 2-decimal rounding at the end.

Roles
Data Scientist
Software Engineer
Data Analyst
Data Engineer
ML Engineer
Companies
GoogleGoogle
AmazonAmazon
Levels
entry
Tags
numpy
44 people are solving this problem
Python LogoPython Editor
Ln 1, Col 1

Input Arguments

Edit values below to test with custom inputs

You need tolog in/sign upto run or submit