0

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?

Questant
  • 1
  • 2
  • 2
    [Yes, it is possible](https://stackoverflow.com/questions/12190184/can-min-max-of-moving-window-achieve-in-on/12195098#12195098) – MBo Jun 01 '23 at 08:21
  • That will work. @MBo since you are the author of the original answer, if you answer again here, perhaps with a link to the original and a brief synopsis, I can mark it as accepted. – Questant Jun 02 '23 at 18:10

0 Answers0