Given a stream of real numbers, it is simple to keep track of the maximum value across the entire history of the stream.
However, I am running into difficulty calculating the maximum of the last n
numbers in the stream. So for the stream {5, 7, 3, 6, 2, 0, 1}
, with n = 3
, the maximum at each index would be {5, 7, 7, 7, 6, 6, 2}
Specifically, while it would be simple to create a list of the past n
values and calculate the maximum of that list as needed, I can not envision a means of doing so without storing such a possibly large list. Is a more efficient implementation possible?