Level 2 · Core Data StructuresBUILD YOUR INTUITION
Deque
Remove or add candidates at either end to maintain a useful frontier, such as decreasing values for window maxima.
THE MENTAL MODELWhen should this come to mind?
Remove or add candidates at either end to maintain a useful frontier, such as decreasing values for window maxima.
Sliding-window maximumExpire oldest candidatesRemove dominated recent candidates What makes it work
Store indices to distinguish expiration from value comparisons. An array with a head cursor avoids costly front shifts but retains consumed storage.
When to choose something else
Arbitrary priority changes need a different structure; a monotonic deque requires a proof that discarded candidates cannot become useful again.
See the pattern in action
Change the input. Follow the state. Make it yours.