From ebb67452bbb7d37521847c10b11dc1e86f98b762 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 29 Jun 2026 05:15:32 -0600 Subject: [PATCH] adding updates --- .../round_1/06_sliding_window_maximum.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/my_project/interviews/google_top_exercises/round_1/06_sliding_window_maximum.py diff --git a/src/my_project/interviews/google_top_exercises/round_1/06_sliding_window_maximum.py b/src/my_project/interviews/google_top_exercises/round_1/06_sliding_window_maximum.py new file mode 100644 index 00000000..eb084297 --- /dev/null +++ b/src/my_project/interviews/google_top_exercises/round_1/06_sliding_window_maximum.py @@ -0,0 +1,26 @@ +from typing import List +from collections import deque + + +class Solution: + def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]: + # Monotonic deque of indices, values in decreasing order. + # Front always holds the index of the current window's max. + answer = list() + dq = deque() + + for i, num in enumerate(nums): + # Drop indices whose values can never be the max again. + while dq and nums[dq[-1]] <= num: + dq.pop() + dq.append(i) + + # Drop the front if it has slid out of the window. + if dq[0] <= i - k: + dq.popleft() + + # Start recording once the first full window is formed. + if i >= k - 1: + answer.append(nums[dq[0]]) + + return answer \ No newline at end of file