Step 1: Start with empty deque, process first element (2 at index 0)
Deque: [0]
Window: [2] (indices 0 to 0)
Why: Add first element index to deque as starting point
Step 2: Process element 1 at index 1, remove smaller elements from back
Deque: [0, 1]
Window: [2, 1] (indices 0 to 1)
Why: 1 is smaller than 2, so keep both; 1 might be max in future windows
Step 3: Process element 3 at index 2, remove smaller elements from back (1)
Deque: [0, 2]
Window: [2, 1, 3] (indices 0 to 2)
Why: 3 is bigger than 1, so remove 1; 3 is current max candidate
Step 4: Process element 4 at index 3, remove smaller elements from back (3)
Deque: [0, 3]
Window: [2, 1, 3, 4] (indices 0 to 3)
Why: 4 is bigger than 3, so remove 3; 4 is max in current window
Step 5: Window reached size 4, record max (value at deque front index 0 = 2)
Max so far: 2
Deque: [0, 3]
Why: Front of deque always holds index of max element in current window
Step 6: Slide window: process element 6 at index 4, remove smaller elements from back (4, 3, 1)
Deque: [4]
Window: [1, 3, 4, 6] (indices 1 to 4)
Why: 6 is bigger than 4, remove 4; 6 is new max candidate
Step 7: Remove indices out of window range (index 0 is out of window 1 to 4)
Deque: [4]
Window: [1, 3, 4, 6]
Why: Remove indices that are no longer in the current window
Step 8: Record max (value at deque front index 4 = 6)
Max so far: 2, 6
Deque: [4]
Why: Max for current window is at front of deque
Step 9: Process element 3 at index 5, smaller than 6, add to back
Deque: [4, 5]
Window: [3, 4, 6, 3] (indices 2 to 5)
Why: 3 is smaller than 6, keep both for future windows
Step 10: Slide window, remove indices out of range (index 1 out of window 2 to 5)
Deque: [4, 5]
Window: [3, 4, 6, 3]
Why: Remove indices no longer in window
Step 11: Record max (value at deque front index 4 = 6)
Max so far: 2, 6, 6
Deque: [4, 5]
Why: Max is at front of deque
Step 12: Process element 8 at index 6, remove smaller elements from back (3 at index 5, 6 at index 4)
Deque: [6]
Window: [4, 6, 3, 8] (indices 3 to 6)
Why: 8 is bigger than 3 and 6, remove them; 8 is new max candidate
Step 13: Slide window, remove indices out of range (index 2 out of window 3 to 6)
Deque: [6]
Window: [4, 6, 3, 8]
Why: Remove indices no longer in window
Step 14: Record max (value at deque front index 6 = 8)
Max so far: 2, 6, 6, 8
Deque: [6]
Why: Max is at front of deque
Step 15: Process element 9 at index 7, remove smaller elements from back (8 at index 6)
Deque: [7]
Window: [6, 3, 8, 9] (indices 4 to 7)
Why: 9 is bigger than 8, remove 8; 9 is new max candidate
Step 16: Slide window, remove indices out of range (index 3 out of window 4 to 7)
Deque: [7]
Window: [6, 3, 8, 9]
Why: Remove indices no longer in window
Step 17: Record max (value at deque front index 7 = 9)
Max so far: 2, 6, 6, 8, 9
Deque: [7]
Why: Max is at front of deque
Step 18: Process element 10 at index 8, remove smaller elements from back (9 at index 7)
Deque: [8]
Window: [3, 8, 9, 10] (indices 5 to 8)
Why: 10 is bigger than 9, remove 9; 10 is new max candidate
Step 19: Slide window, remove indices out of range (index 4 out of window 5 to 8)
Deque: [8]
Window: [3, 8, 9, 10]
Why: Remove indices no longer in window
Step 20: Record max (value at deque front index 8 = 10)
Max so far: 2, 6, 6, 8, 9, 10
Deque: [8]
Why: Max is at front of deque
Step 21: Process element 12 at index 9, remove smaller elements from back (10 at index 8)
Deque: [9]
Window: [8, 9, 10, 12] (indices 6 to 9)
Why: 12 is bigger than 10, remove 10; 12 is new max candidate
Step 22: Slide window, remove indices out of range (index 5 out of window 6 to 9)
Deque: [9]
Window: [8, 9, 10, 12]
Why: Remove indices no longer in window
Step 23: Record max (value at deque front index 9 = 12)
Max so far: 2, 6, 6, 8, 9, 10, 12
Deque: [9]
Why: Max is at front of deque
Step 24: Process element 56 at index 10, remove smaller elements from back (12 at index 9)
Deque: [10]
Window: [9, 10, 12, 56] (indices 7 to 10)
Why: 56 is bigger than 12, remove 12; 56 is new max candidate
Step 25: Slide window, remove indices out of range (index 6 out of window 7 to 10)
Deque: [10]
Window: [9, 10, 12, 56]
Why: Remove indices no longer in window
Step 26: Record max (value at deque front index 10 = 56)
Max so far: 2, 6, 6, 8, 9, 10, 12, 56
Deque: [10]
Why: Max is at front of deque
Result: Final max values for each window: [2, 6, 6, 8, 9, 10, 12, 56]