Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Moving Average of Speed Stream

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Moving Average of Speed Stream. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given an integer window_size and an array of real numbers speeds representing vehicle speed readings in arrival order, return an array where each element is the moving average of the last at most window_size readings seen so far. The result at index i should be the average of the current reading and up to the previous window_size - 1 readings.

Constraints

  • 1 <= window_size <= 10^5
  • 0 <= len(speeds) <= 10^5
  • -10^6 <= speeds[i] <= 10^6
  • Return averages as floating-point values

Function Signature

def moving_average_speed(window_size, speeds):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output