Stock Span Problem
Medium

Problem Statement

The stock span problem is a financial problem where we have a series of n daily price quotes for a stock and we need to calculate the span of the stock's price for each day. The span of the stock's price on a given day is defined as the maximum number of consecutive days (including the given day and going backwards) for which the price of the stock on those days is less than or equal to its price on the given day.

Examples

1Example 1
Input:
{ "price": [ 100, 80, 60, 70, 60, 75, 85 ] }
Output:
[ 1, 1, 1, 2, 1, 4, 6 ]
2Example 2
Input:
{ "price": [ 10, 4, 5, 90, 120, 80 ] }
Output:
[ 1, 1, 2, 4, 5, 1 ]
3Example 3
Input:
{ "price": [ 60, 70, 80, 100, 90, 75, 80, 120 ] }
Output:
[ 1, 2, 3, 4, 1, 1, 2, 8 ]
Loading...

Sign in to Run Code and Submit