I Hate Overlaps
InterviewTime limit1sMemory limit1024 MB
Given a sequence and a limit K, find the length of the longest contiguous subarray where no value appears more than K times.
- Level
Medium5 of 10
- Topics
- Sliding window, Two pointers, Hash map, Array
- Solved
- No attempts yet
Problem
Dohyun has a case of "hongdae disease" and hates overlaps. In particular, he hates sequences that contain several copies of the same element. For Dohyun, you want to find the length of the longest contiguous subsequence that contains at most copies of any one element.
You are given a sequence of length made of positive integers at most . Write a program that finds the length of the longest contiguous subsequence containing at most copies of any one integer.
Input
The first line gives the integers () and ().
The second line gives ().
Output
Print the length of the longest contiguous subsequence that satisfies the condition.
Notes
A contiguous subsequence is a subsequence formed by selecting one or more consecutive elements of the sequence.
When , is a contiguous subsequence and is not.