Longest Even Contiguous Subsequence (Large)
InterviewTime limit1sMemory limit1024 MB
Given a sequence, delete at most K elements so that some remaining contiguous run consists only of even numbers, and report the longest such run.
- Level
Medium5 of 10
- Topics
- Sliding window, Two pointers, Array, Greedy
- Solved
- No attempts yet
Problem
There is a sequence of length . Every element of is a positive integer.
You may delete an element at any position in , at most times in total.
For example, suppose is given as follows.
Sequence S : 1 2 3 4 5 6 7 8
If you delete the 4th element, 4, then becomes the following.
Sequence S : 1 2 3 5 6 7 8
After deleting at most elements from , find the maximum length of a contiguous subsequence consisting only of even numbers.
Input
The first line contains the length of the sequence and the maximum number of deletions , separated by a space.
The second line contains the integers that make up the sequence , separated by spaces.
Output
Print the maximum length of a contiguous subsequence consisting only of even numbers after deleting at most elements from .
Constraints
- element value