Stock Span Problem (Solution in Java)
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 stock’s price for all n days. The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day(including), for which the price of the stock on the current day is less than or equal to its price on the given day. For example, if an array of 7 days prices is given as {100, 80, 60, 70, 60, 75, 85}, then the span values for corresponding 7 days are {1, 1, 1, 2, 1, 4, 6}. Explanation to the given example: On 0th day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens. On 1st day only the current day where we find that stock price is less than or equal to it so for 1 consecutive day(current day) this happens. On 2nd day only the current day where we find that stock price is less than or equal ...