other.sliding_window_maximum ============================ .. py:module:: other.sliding_window_maximum Functions --------- .. autoapisummary:: other.sliding_window_maximum.sliding_window_maximum Module Contents --------------- .. py:function:: sliding_window_maximum(numbers: list[int], window_size: int) -> list[int] Return a list containing the maximum of each sliding window of size window_size. This implementation uses a monotonic deque to achieve O(n) time complexity. Args: numbers: List of integers representing the input array. window_size: Size of the sliding window (must be positive). Returns: List of maximum values for each valid window. Raises: ValueError: If window_size is not a positive integer. Time Complexity: O(n) - each element is added and removed at most once Space Complexity: O(k) - deque stores at most window_size indices Examples: >>> sliding_window_maximum([1, 3, -1, -3, 5, 3, 6, 7], 3) [3, 3, 5, 5, 6, 7] >>> sliding_window_maximum([9, 11], 2) [11] >>> sliding_window_maximum([], 3) [] >>> sliding_window_maximum([4, 2, 12, 3], 1) [4, 2, 12, 3] >>> sliding_window_maximum([1], 1) [1]