By Soham Ghosh
Given an array of n daily prices for a stock, this project calculates the span of stock's price for all n days using Java.
The project uses Stack class which models and implements the Stack data structure through its predefined methods such as push(), pop(), peek() and Scanner class for user input. The stack stores the days from 0 to n-1 in an order such that when the stock price of day to be pushed is greater than equal to the stock price of the top, we pop elements from the stack until this condition is negated.
The span of the stock's price on a given day is defined as the maximum number of consecutive days including the given day, for which the stock price on current day is less than or equal to the price on the given day. The span value for each price is given as: span[i] = i - stack.top().
Enter the number of days
Enter the stock prices
The stock span values are: