Repository navigation
Conversation
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
The positive-only sliding window misses valid answers on signed input. For example,
minimum_subarray_sum(4, [-2, 4])returns 0, andminimum_subarray_sum(3, [1, -1, 3])returns 3. In each case the final value alone meets the target.Track increasing prefix sums in a deque. Remove starts that already meet the target after recording their length, and discard starts that are dominated by a later prefix. Each index enters and leaves the deque at most once. The search runs in O(n) time and uses up to O(n) auxiliary space.
All 15 existing doctests pass. I compared the results to exhaustive enumeration for 234,372 combinations of signed lists and targets, including zero and negative targets. Ruff lint and formatting checks passed. AI-assisted change.
Checklist