Skip to content

Conversation

@P09s
Copy link

@P09s P09s commented Jan 12, 2026

Implements the classic sliding window maximum problem (LeetCode 239) using a monotonic deque for O(n) time.

Features:

  • Full Google-style docstring with examples and complexity analysis
  • Type hints
  • Doctests for normal + edge cases
  • Clean, educational code following repo standards

Ready for review!

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Jan 12, 2026
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Jan 12, 2026
@P09s
Copy link
Author

P09s commented Jan 12, 2026

Hi maintainers! @poyea @cclauss @mindaugl

  • Updated the implementation with modern type hints (list[int], deque[int]) to satisfy Ruff rules (UP006/UP035)
  • Fixed end-of-file newline
  • All CI checks are now green (ruff, pre-commit.ci, build, docs)
  • Tests pass, label removed automatically

Ready for review! Would appreciate any feedback
Thanks!

from collections import deque


def sliding_window_maximum(numbers: list[int], window_size: int) -> list[int]:
Copy link
Member

Choose a reason for hiding this comment

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

What's the difference between this and maths/max_sum_sliding_window.py?

Copy link
Author

Choose a reason for hiding this comment

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

Hi @poyea, thanks for the review!

Great question — these two are related (both use sliding window idea), but they solve completely different problems:

  • maths/max_sum_sliding_window.py finds the maximum sum of any single window of size k → returns one integer (the largest possible sum among all k-sized subarrays). It uses a simple running sum technique.

  • My PR adds other/sliding_window_maximum.py which finds the maximum element in every sliding window of size k → returns a list of max values (one per window position). This is the classic "Sliding Window Maximum" problem (LeetCode 239), solved efficiently with a monotonic deque to track the current maximum in O(1) per step.

Example to show the difference:
Input: nums = [1, 3, -1, -3, 5, 3, 6, 7], k = 3

  • Your existing file would return the single max sum (e.g. max of 1+3+(-1)=3, 3+(-1)+(-3)=-1, etc. → probably 5+3+6=14)
  • My new file returns [3, 3, 5, 5, 6, 7] — the max element in each of the 6 overlapping windows

They have different outputs, different goals, and use different internal logic (deque vs simple sum update). No overlap/duplication — this adds a popular, missing hard problem from LeetCode/competitive programming.

Happy to make any adjustments or add more comments if needed!

@P09s P09s requested a review from poyea January 13, 2026 05:48
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.

3 participants