Practice Discrete Math

Algorithms / Monotonic Queue Sliding Window

Least You Need to Know: Monotonic Queues and Sliding-Window Extremes

A monotonic deque keeps the current window's best candidates in order, so the front always holds the maximum or minimum. It is the standard pattern for sliding-window extrema because it supports both expiration from the left and dominance cleanup from the right.

جو کم از کم جاننا ضروری ہے

اہم علامتیں

window [L, R] current contiguous range under consideration
deque front current max or min for the window
dominated can never win while a better later candidate remains valid

مختصر حل شدہ مثال

  • For sliding-window maximum, maintain deque values in decreasing order.
  • Before appending a new index, pop smaller values from the back because the new value dominates them.
  • When the left boundary moves, pop the front if that index expired.
  • Then the front is the current window maximum.

عام غلطیاں

اس قسم کے سوال کو کیسے پہچانیں

Next recommended lesson

Continue through this topic with Least You Need to Know: Monotonic Stacks for Range Boundaries and Histogram Areas.

Least You Need to Know: Monotonic Stacks for Range Boundaries and Histogram Areas

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

مشق شروع کریں