I have a list of integers with the maximum element, and I need to track the maximum element in the list:
[3, 1, 2] (3 is the max)
Each time period, I get a new random element, add it to the end of the list and delete the first element of the list in constant time. So, at the end of the current period, my list will look like this:
[3, 1, 2] (3 is the max) -> [3, 1, 2, -5] (don't care about max at this moment) -> [1, 2, -5] (now 2 is the max)
I could keep the priority queue specified in the values ββin the list by typing and deleting O (log (n)), but I was interested to know if there is a more efficient (possibly [amortized] constant time?).
source share