Problems > Most Distinct Window

Most Distinct Window

Difficulty: 1400 2000 ms 128 MB

sliding-window

Among all windows of exactly K elements, print the largest number of distinct values any window contains.

Input: the first line has N and K; the second line has N integers.

Output: the maximum count of distinct values in a size-K window.

Constraints:

  • 1 ≤ K ≤ N ≤ 104
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
7 3
1 2 1 3 4 2 3
Output 1
3
Input 2
3 3
5 5 5
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.