Add new array algorithms : Maximum Circular Subarray and Sliding Window Maximum #12307
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.
Added Files:
max_subarray_circular.py: Implements the maximum sum subarray in a circular array using an optimized O(n) approach, adapting Kadane’s algorithm for circular structures.
sliding_window_maximum.py: Efficient sliding window maximum finder using a deque for optimal O(n) complexity. Both implementations include comprehensive doctests.
References:
Maximum Circular Subarray: https://en.wikipedia.org/wiki/Maximum_subarray_problem#Circular_array
Sliding Window Maximum: https://en.wikipedia.org/wiki/Sliding_window_protocol
Describe your change:
(1) Add new algorithms to solve distinct array manipulation problems.
NO Fix a bug or typo in an existing algorithm?
NO Add or change doctests?
NO Documentation change?
Checklist:
I have read and followed CONTRIBUTING.md
This PR is entirely my own work and original.
I understand that PRs failing automated tests will not be merged.
Although this PR adds two files, each solves different yet related array manipulation tasks, which will streamline review.
Both files are located in existing directories, and all naming conventions align with repo guidelines.
Function parameters and returns use type hints, and doctests pass automated testing.
Each algorithm includes a link for further reference.