Algorithm · Atlassian · Medium
Given a positive integer N and an unbounded sequence of integers, create a data structure/class that accepts each incoming value and reports the mean of the latest N values. Until N values have arrived, compute the mean using every value received to that point. Requirements Operation: next(x): accept the next integer x and return the updated rolling average. Target runtime: O(1) for each call to next. Target memory usage: O(N). Follow-up When newer values should contribute…
Checking your access…