Another substring

3.3

3 votes
Algorithms, Approved, Dynamic Programming, Hard, Ready, Recruit, Two pointer
Problem

You are given an array A. The array contains all the elements in the range of 1 to K.

Determine the minimum size of the subarray that contains all the K distinct elements.

Input format

  • First line: T denoting the number of test cases
  • For each test case:
    • First line: N denoting the length of the array and K
    • Next line: N integers denoting the elements of the array

Output format
Print the minimum size of the subarray that contains all the K distinct elements.

Constraints
1T101N1000001K10000

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

There's a continuous segment 2,3,1 which contains all the K distinct elements.

Editor Image

?