Loading...
Loading...
Loading...
A trading screen shows n prices. For every stretch of k prices in a row, print the highest price. The input can be large, so do not rescan every stretch.
Example
Input
8 3 1 3 -1 -3 5 3 6 7
Output
3 3 5 5 6 7
The highest prices of the six stretches are 3 3 5 5 6 7.
Try the problem first. Open one hint at a time.
The maximum of a stretch can leave, so a single variable is not enough.
Keep a deque of indexes whose values decrease from the front; the front is the maximum.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor