Given an array of integers and a window size, find the maximum value in each window as it slides through the array.
Explanation: For window size 3, the maximum in each window is calculated as the window slides through the array: Window 1: [4, 2, 9], max = 9; Window 2: [2, 9, 7], max = 9; Window 3: [9, 7, 5], max = 9; Window 4: [7, 5, 3], max = 7; Window 5: [5, 3, 1], max = 5.
Explanation: For window size 2, the maximum in each window is: Window 1: [1, 3], max = 3; Window 2: [3, 5], max = 5; Window 3: [5, 2], max = 5; Window 4: [2, 6], max = 6; Window 5: [6, 4], max = 6.
Maximum in each window using deque
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak