• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 10, 2022 |39.0K Views
The Stock Span Problem
  Share  3 Likes
Description
Discussion

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 the 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, for which the price of the stock on the current day is less than its price on the given day.

Example:

Input: N = 7, price[] = [100 80 60 70 60 75 85]


Output: 1 1 1 2 1 4 6


Explanation: Traversing the given input span for 100 will be 1, 80 is smaller than 100 so the span is 1, 60 is smaller than 80 so the span is 1, 70 is greater than 60 so the span is 2 and so on. Hence the output will be 1 1 1 2 1 4 6.

The Stock Span Problem : https://www.geeksforgeeks.org/the-stock-span-problem/