Problem
- I have fixed length FIFO queue of integer values.
- Everytime I push new value into it, oldest one is removed.
- Queue must be able to tell, after every insertion & removal operation, what is currently the biggest value in it.
Question
Is there algorithm better than doing loop over all queue elements every time?
After accept update
Because of limited domain of integers in my application, I was also thinking about sparse histogram, containing counts of given value in my queue. So every time value arrives I increment its value in histogram, and decrement when given value is removed. Then to get max/min I need only to get first/last histogram index with non zero count.