119. Minimum in Every Window
Challenge1000 ms256 MBSolved by 0%
Print the minimum of every window of k consecutive elements, in order,
separated by single spaces.
There are n − k + 1 windows, so that is how many values you print.
Constraints - `1 ≤ k ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000`
Input
The first line contains two integers n and k.
The second line contains n space-separated integers.
Output
Print n - k + 1 integers on ONE line, separated by single spaces, the minimum of each window, left to right.
Input5 3
1 3 2 5 4
Output1 2 2
Notehas three windows with different minimums
Input5 1
3 1 4 1 5
Output3 1 4 1 5
Notehas a window of one, so every element is its own minimum
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.