AmazonOA #206
Get Max Racers
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersHashing
Remove at most k racers; the remaining racers keep their relative order. Find the number of racers in the longest contiguous run of the same speed in the remaining sequence. Removed racers do not count toward the answer.
Input
The first line contains n k; the second line contains the speeds. 1≤n≤300000, 1≤k≤n. The original text had no numeric bounds on speed; this site uses speeds 1..10^9.
Output
Output a single integer, the answer.
Example 1
Input:
6 2
1 4 4 2 2 4
Output:
3
Example 2
Input:
3 3
1 2 3
Output:
1
Example 3
Input:
3 1
5 5 5
Output:
3
Example notes
The answers are 3, 1 and 3.
Editorial
Loading solution…