A cold-chain logger records n temperature-deviation readings in order. A reading below zero (strictly negative) is an alarm. For every contiguous window of exactly k consecutive readings, taken from left to right, report the first alarm reading (the earliest strictly-negative value) inside that window. If a window contains no strictly-negative reading, report 0 for it.
Line 1: two integers n and k.
Line 2: n space-separated integers, the readings in order.
One line with n - k + 1 space-separated integers: for each window (left to right), the first strictly-negative reading, or 0 if none.
Example 1
Input
5 3 2 -1 3 -4 5
Expected
-1 -1 -4
Explanation
Windows: [2,-1,3] -> first negative is -1; [-1,3,-4] -> first negative is -1; [3,-4,5] -> first negative is -4.
Example 2
Input
4 2 1 2 3 4
Expected
0 0 0
Explanation
No window contains a negative reading, so every answer is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →