414. Subarrays With Exactly K Odd Numbers
MediumPrefix SumHash Map
Count the contiguous subarrays that contain exactly k odd numbers.
Input format
Line 1: n k Line 2: n integers
Output format
The count.
Example 1
Input
5 3 1 1 2 1 1
Output
2
Example 2
Input
3 1 2 4 6
Output
0
Constraints
1 ≤ k ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…