Interview Question

Interview Seattle, WA

Write a class that takes in a window size (n) in its

  constructor. The only method in the class takes in an integer, adds it into a sequence of numbers with that value, and returns the average of the last n values inserted into the sequence. Do not iterate over the sequence to calculate the average. Couldn't use STL. For example, if window size (n) is 2: update(1) returns 1 update(2) returns 1.5 update(3) returns 2.5 update(4) returns 3.5
Answer

Add Answers or Comments

To comment on this, Sign In or Sign Up.