Longest Even Contiguous Subsequence (small)
InterviewTime limit1sMemory limit1024 MB
Delete at most K elements from a sequence, then report the longest contiguous run of even numbers possible.
- 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 pick an element at any position in and delete it, at most times in total.
For example, suppose is given as follows.
S : 1 2 3 4 5 6 7 8
If you delete the 4th element, 4, the sequence becomes the following.
S : 1 2 3 5 6 7 8
Given a sequence obtained by 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 , separated by spaces.
Output
Print the maximum length of a contiguous subsequence consisting only of even numbers in a sequence obtained by deleting at most elements from .
Constraints
- element value