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

Sign in to watch this lesson
Algorithms - Linear Data Structures · 4:28
A stack that stays rising from bottom to top answers "nearest smaller to the left" for every element in one linear pass: each new bar knocks off the bars at least as tall, and whatever is left on top is its answer. We trace it on [3, 7, 8, 4, 2, 6, 5], cover the four variants and the tie rules, then let the same stack hand every bar of the histogram [2, 1, 5, 6, 2, 3] both of its boundaries to find the largest rectangle (10), and finish with the contribution technique for the sum of subarray minimums. Timings on this Mac compare the stack with the quadratic scans.