Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Algorithms
Algorithmshard

What is a monotonic queue and how does it solve sliding window max in O(n)?

Tags
#deque#monotonic-queue#sliding-window#big-o
Back to categoryPractice quiz

Answer

A monotonic queue is a deque that keeps elements in decreasing (or increasing) order. For sliding window maximum, you pop smaller elements from the back when adding a new one, so the front is always the max. You also pop from the front when it leaves the window. Each element is added and removed at most once, so total time is O(n).

Related questions

Algorithms
Quickselect: what is it used for and what is its expected complexity?
#quickselect#selection#partition
Algorithms
Sliding window: what is it and when is it better than nested loops?
#sliding-window#two-pointers#complexity
Algorithms
Counting sort: when can it be faster than O(n log n) sorting?
#counting-sort#sorting#stability
Algorithms
Kruskal vs Prim for MST — how do they differ?
#mst#kruskal#prim
Algorithms
Randomized pivot in QuickSort/Quickselect — why does it help?
#randomization#quicksort#quickselect
Algorithms
What is a monotonic stack and what kind of problems does it solve?
#stack#monotonic-stack#next-greater