Feature #8: Find Intervals

Implement the "Find Intervals" feature for our "Stocks" project.


We are given the price predictions, prices, of a stock over a future time window. We are interested in making a profit by selling the stock at a higher price.

There are n intervals in the time window, where each ithi^{th} interval represents a stock’s predicted price for that interval. Our goal is to return an array, intervals, such that intervals[i] is the minimum number of intervals after the ith interval when the price will increase. If there is no time interval for which this is possible, we will keep intervals[i] == 0 instead.

The following examples may clarify these requirements:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.