Stock Span Problem

You are given an array prices, where prices[i] is the price of a stock on day i, listed in the order the days occurred. For each day i, the span is the largest number of consecutive days ending at day i for which the price never exceeded prices[i].

To measure it, start at day i, which always counts as one day, then walk backwards one day at a time. Keep including a day while its price is less than or equal to prices[i], and stop at the first day whose price is strictly greater than prices[i], or when the start of the array is reached.

Return an array spans of the same length as prices, where spans[i] is the span of day i. Day 0 always has span 1.

Examples
Input: [100,80,60,70,60,75,85]
Output: [1,1,1,2,1,4,6]
Hints

Stock Span Problem

You are given an array `prices`, where `prices[i]` is the price of a stock on day `i`, listed in the order the days occurred. For each day `i`, the **span** is the largest number of consecutive days ending at day `i` for which the price never exceeded `prices[i]`.