Problems > Exactly K Odd Numbers

Exactly K Odd Numbers

Difficulty: 1600 5000 ms 128 MB

two-pointers

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.