At Most K Odd Numbers
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
Discussion (opens after you solve — no spoilers before)
No comments yet.