Problems > At Most K Odd Numbers

At Most K Odd Numbers

Difficulty: 1400 3000 ms 128 MB

two-pointers

Find the longest contiguous subarray containing at most K odd numbers.

Input: the first line has N and K; the second line has N integers.

Output: the maximum length of a window with ≤ K odd values.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ K ≤ N
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
6 1
2 4 3 6 8 5
Output 1
5
Input 2
3 0
1 2 4
Output 2
2

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.