0

The Stock Span Problem

 1 year ago
source link: https://www.geeksforgeeks.org/videos/the-stock-span-problem/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The Stock Span Problem

The Stock Span Problem
  • 10/06/2022

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/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK