Exactly K Odd Numbers
Count the contiguous subarrays containing exactly K odd numbers.
Input: the first line has N and K; the second line has N integers.
Output: the number of subarrays with exactly K odd values.
Constraints:
- 1 ≤ N ≤ 105
- 0 ≤ K ≤ N
- |ai| ≤ 109
Sample Tests
Input 1
4 1 1 2 3 4
Output 1
6
Input 2
3 0 2 4 6
Output 2
6
Discussion (opens after you solve — no spoilers before)
No comments yet.