Description

Design an algorithm that collects daily price quotes for some stock and returns the span of that stock's price for the current day. The span is the number of consecutive days the price was less than or equal to today's price.

Examples

Input:prices = [100, 80, 60, 70, 60, 75, 85]
Output:[1, 1, 1, 2, 1, 4, 6]
Explanation:

Span calculated for each day.

Input:prices = [1]
Output:[1]
Explanation:

Edge case with a single-element array.

Input:prices = [50, 60, 70, 65, 80, 55, 90]
Output:[1, 2, 3, 1, 5, 1, 7]
Explanation:

Day 1: price=50, span=1 (only itself). Day 2: price=60, span=2 (60≥50 and 60≥60). Day 3: price=70, span=3 (70≥50, 70≥60, 70≥70). Day 4: price=65, span=1 (65<70, so only itself). Day 5: price=80, span=5 (80 is greater than all previous prices 65,70,60,50). Day 6: price=55, span=1 (55<80, so only itself). Day 7: price=90, span=7 (90 is greater than all previous prices).

Constraints

  • 1 ≤ price ≤ 10⁵
  • At most 10⁴ calls to next().

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!