Skip to content

Added Maximum Sliding Window algorithm using deque for efficient O(n) solution. #5848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 26, 2024

Conversation

pranayh24
Copy link
Contributor

@pranayh24 pranayh24 commented Oct 15, 2024

  • 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 code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 72.34%. Comparing base (3da16a7) to head (2d084f4).

Files with missing lines Patch % Lines
...com/thealgorithms/others/MaximumSlidingWindow.java 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5848      +/-   ##
============================================
+ Coverage     72.32%   72.34%   +0.01%     
- Complexity     4965     4975      +10     
============================================
  Files           651      652       +1     
  Lines         17562    17576      +14     
  Branches       3385     3389       +4     
============================================
+ Hits          12702    12715      +13     
  Misses         4382     4382              
- Partials        478      479       +1     

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

@pranayh24
Copy link
Contributor Author

Pull Request Description
Title: Add Maximum Sliding Window Algorithm Implementation

Overview: This pull request adds an implementation of the Maximum Sliding Window algorithm using a deque (double-ended queue) for efficient O(n) time complexity. The algorithm allows you to find the maximum value in every sliding window of size k in an array of integers.

Key Features:

Efficient Implementation: Utilizes a deque to maintain the indices of useful elements in the current window, allowing for optimal performance.
Input and Output:
Input: An array of integers and a window size k.
Output: An array of the maximum values for each sliding window.
Space Complexity: O(k) for the deque, which holds at most k elements at any time.

Feedback: I welcome any feedback or suggestions for improvements on this implementation.

@pranayh24 pranayh24 marked this pull request as ready for review October 15, 2024 11:12
@pranayh24 pranayh24 marked this pull request as draft October 17, 2024 17:37
@pranayh24 pranayh24 marked this pull request as ready for review October 18, 2024 18:33
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak enabled auto-merge (squash) October 26, 2024 09:17
@siriak siriak merged commit 985c1f9 into TheAlgorithms:master Oct 26, 2024
6 checks passed
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.

4 participants