-
Notifications
You must be signed in to change notification settings - Fork 21k
Open
Labels
Description
What would you like to Propose?
I want to add an implementation of the Stock Span Problem to the Java repository.
The Stock Span Problem is a classic monotonic-stack algorithm that computes, for each day, how many consecutive previous days had a stock price less than or equal to the current day's price. The implementation runs in linear time using a stack of indices.
Issue details
Expected behavior:
Given an array of stock prices, the algorithm should return an array where each position contains the span for that day.
Example:
- prices: [100, 80, 60, 70, 60, 75, 85]
- expected result: [1, 1, 1, 2, 1, 4, 6]
Planned/implemented test coverage:
- mixed example arrays
- increasing prices
- decreasing prices
- repeated equal prices
- empty array
- single-element array
- null input throws
IllegalArgumentException
Additional Information
No response
Reactions are currently unavailable