First Loss in Each Block
profits[i] is a shop's profit on day i, and a negative value is a loss. Look at every block of k consecutive days, from the block that starts on day 0 to the block that ends on the last day. For each block, report its earliest loss, or 0 if it has none.
Return the reports in order. There are len(profits) - k + 1 of them.
Example 1
profits [5,-2,3,-7,4,6]
k 3
returns [-2,-2,-7,-7]
The blocks are [5,-2,3], [-2,3,-7], [3,-7,4] and [-7,4,6].
Example 2
profits [4,0,9]
k 2
returns [0,0]
A profit of 0 is not a loss.
Constraints
1 <= k <= len(profits) <= 100-1000 <= profits[i] <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.