Repository navigation
Conversation
calculate_span([]) raised IndexError because s[0] was set before checking the length. Return an empty list.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
data_structures/stacks/stock_span_problem.py::calculate_spansets[0] = 1before looking at the length, socalculate_span([])raisedIndexErrorinstead of returning an empty list. It now returns[]for an empty price list. Other inputs are unchanged.I added a doctest for the empty list (it fails on
master); the added doctest is the regression evidence for this one function, so I kept it in the same PR. Over 2000 random price lists (0 to 8 items) the result matches a brute-force span.ruff check,ruff format --checkandpython -m doctestpass.Written with the help of Claude Code (Claude Sonnet 5.5).
Checklist