Dashboard
LC #901
Online Stock Span
Pattern · ?AmazonGoogleBloomberg
Problem
Design a class that collects stock prices and returns the span (consecutive days with price ≤ today).
Constraints
- 1 ≤ price ≤ 10⁵
- At most 10⁴ calls to next
Example
- Input
- next calls: [100],[80],[60],[70],[60],[75],[85]
- Output
- [1, 1, 1, 2, 1, 4, 6]
- Why
- 75 has span 4: [60,70,60,75] all ≤ 75. 85 has span 6: all previous ≤ 85
Spot the pattern
Which pattern cracks it?
Hints
One at a time