Approach hintTry it first, then revealHide
Store (price, span) pairs on a stack. When a new price arrives, pop every pair whose price does not exceed it and add their spans to its own before pushing it, so each call is amortised O(1).
Store (price, span) pairs on a stack. When a new price arrives, pop every pair whose price does not exceed it and add their spans to its own before pushing it, so each call is amortised O(1).