Online Stock Span
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Daily closing prices arrive one at a time. For each new price, report its **span**: the number of consecutive days ending today (today included) on which the price was **less than or equal to** today's price.
Implement:
- StockSpanner() creates the tracker.
- next(price) records today's price and returns today's span.
The span is always at least 1. Each call should be amortized O(1).
Examples
Constraints
- 1 <= price <= 10^5
- At most 10^4 calls to `next`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.