Count the contiguous subarrays of nums that contain exactly k odd numbers.
For nums = [1, 1, 2, 1, 1] and k = 3 the answer is 2.
The starter code counts odd numbers in every subarray. It is correct but too slow for long lists.
Example 1
Input:
number_of_subarrays([1, 1, 2, 1, 1], 3)
Output:
2
Example 2
Input:
number_of_subarrays([2, 4, 6], 1)
Output:
0
0 <= len(nums) <= 2000000 <= k <= len(nums)1 <= nums[i] <= 10**5No results yet
Run your code to check it against the examples, or submit to run every test.