Loading...
Loading...
Loading...
Given a list of numbers and a window size k, slide the window from left to right. For every position of the window, print the largest number inside it.
Example 1
Input
8 3 1 3 -1 -3 5 3 6 7
Output
3 3 5 5 6 7
The maxima are 3, 3, 5, 5, 6 and 7.
Example 2
Input
3 1 4 2 9
Output
4 2 9
Try the problem first. Open one hint at a time.
Keep a deque of indexes. Their values should fall from front to back.
Pop smaller values from the back before pushing, and pop the front if it left the window.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor