⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 23s17 days 22 hours 20 minutes 23 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 23s17 days 22 hours 20 minutes 23 seconds.

Sign in to watch this lesson
Algorithms - Arrays · 4:45
A stack keeps its minimum in O(1) by caching the minimum below every element, but a queue removes from the other end. We slide a window of 3 over [1, 3, -1, -3, 5, 3, 6, 7] with a monotone deque whose values climb like a staircase: newer, smaller values bulldoze older ones off the back and expired indices fall off the front, so every window minimum is read from the front in amortized O(1). Then we build a queue from two min-stacks, which works for any associative operation such as gcd or OR, and measure the rescan against the deque on a million values.