Skip to content

feat: add StockSpanProblem algorithm#7312

Open
oleksii-tumanov wants to merge 1 commit intoTheAlgorithms:masterfrom
oleksii-tumanov:stock-span-problem
Open

feat: add StockSpanProblem algorithm#7312
oleksii-tumanov wants to merge 1 commit intoTheAlgorithms:masterfrom
oleksii-tumanov:stock-span-problem

Conversation

@oleksii-tumanov
Copy link
Contributor

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Description

Adds a monotonic-stack implementation of the Stock Span Problem.

The implementation:

  • computes the span for each day in linear time
  • returns an array of spans for the input prices
  • validates null input

Closes #7311

Test Case

Validated with:

  • mixed prices: [10, 4, 5, 90, 120, 80] -> [1, 1, 2, 4, 5, 1]
  • increasing prices
  • decreasing prices
  • repeated equal prices
  • empty array
  • single-element array
  • null input throws IllegalArgumentException

Commands used:

  • mvn -Dtest=StockSpanProblemTest test
  • mvn -DskipTests checkstyle:check

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.45%. Comparing base (5e06b15) to head (105aae5).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7312   +/-   ##
=========================================
  Coverage     79.44%   79.45%           
- Complexity     7064     7070    +6     
=========================================
  Files           788      789    +1     
  Lines         23129    23139   +10     
  Branches       4548     4551    +3     
=========================================
+ Hits          18375    18385   +10     
  Misses         4022     4022           
  Partials        732      732           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oleksii-tumanov oleksii-tumanov marked this pull request as ready for review March 14, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Add Stock Span Problem algorithm in Java

2 participants