Skip to content

Commit e4f9d6d

Browse files
committed
feat: add sliding window maximum using monotonic deque
1 parent ecf074d commit e4f9d6d

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

other/sliding_window_maximum.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from collections import deque
2-
from typing import Deque, List
32

43

5-
def sliding_window_maximum(numbers: List[int], window_size: int) -> List[int]:
4+
def sliding_window_maximum(numbers: list[int], window_size: int) -> list[int]:
65
"""
76
Return a list containing the maximum of each sliding window of size window_size.
87
@@ -38,8 +37,8 @@ def sliding_window_maximum(numbers: List[int], window_size: int) -> List[int]:
3837
if not numbers:
3938
return []
4039

41-
result: List[int] = []
42-
index_deque: Deque[int] = deque()
40+
result: list[int] = []
41+
index_deque: deque[int] = deque()
4342

4443
for current_index, current_value in enumerate(numbers):
4544
# Remove the element which is out of this window

0 commit comments

Comments
 (0)