Stretches With K Odd Values
Count the contiguous, non-empty stretches of nums that contain exactly k odd numbers. Stretches at different positions count separately even when they hold the same values.
Return the count. With k = 0, count the stretches made of even numbers only.
Example 1
nums [1,1,2,1,1]
k 3
returns 2
The stretches with exactly three odd numbers are 1, 1, 2, 1 and 1, 2, 1, 1.
Example 2
nums [2,4,6]
k 1
returns 0
There is no odd number at all, so no stretch has one.
Constraints
0 <= len(nums) <= 100-1000 <= nums[i] <= 10000 <= k <= len(nums)
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.