Sliding Window Maximum Using Deque
📖 Scenario: Imagine you are analyzing the temperature readings of a city over several days. You want to find the highest temperature in every 3-day window to understand the hottest periods.
🎯 Goal: Build a program that uses a deque (double-ended queue) to find the maximum temperature in every sliding window of size 3 from a list of daily temperatures.
📋 What You'll Learn
Create a list called
temperatures with the exact values: [4, 3, 5, 2, 1, 6, 7]Create a variable called
window_size and set it to 3Use a
deque from the collections module to help find the maximum in each sliding windowPrint the list of maximum values for each sliding window
💡 Why This Matters
🌍 Real World
Sliding window maximum is useful in analyzing time series data like temperatures, stock prices, or sensor readings to find local peaks efficiently.
💼 Career
This technique is often asked in coding interviews and used in performance-critical applications where quick data analysis over moving windows is required.
Progress0 / 4 steps