Price Drop Forecast
Groww aims to provide its users with insightful market data. One such insight is forecasting potential short-term price drops. This problem asks you to build a tool that, for each day, predicts how many days it will take for the stock price to drop below or equal to its current level. This can help users identify potential support levels or exit points.
Implement the function priceDropForecast that takes an array of daily stock prices prices and returns an array where each element result[i] represents the number of days until the price prices[i] drops to a value less than or equal to prices[i]. If the price never drops below or equals prices[i] for any future day, result[i] should be -1.
prices: An array of positive integers, prices[i] representing the stock price on day i.result of the same length as prices. result[i] is the number of days until prices[i] drops below or equals itself, or -1 if it never does.prices[i] drops to prices[j] where j > i and prices[j] <= prices[i], the number of days is j - i.j).Examples
Example 1
Input:
prices = [10, 8, 12, 11, 13, 9]
Output:
[1, -1, 1, 2, 1, -1]
Note:
Example 2
Input:
prices = [7, 6, 5, 4, 3, 2, 1]
Output:
[1, 1, 1, 1, 1, 1, -1]
Note:
Each day, the price drops to the next day's price. For the last day, no future drop.
Example 3
Input:
prices = [1, 2, 3, 4, 5]
Output:
[-1, -1, -1, -1, -1]
Note:
The prices are strictly increasing, so no future price ever drops below or equals the current price.
Constraints
1 <= prices.length <= 10^51 <= prices[i] <= 10^9prices will only contain positive integers.Loading editor...