Bob's Quest

3.7

7 votes
C++, Greedy Algorithms, Algorithms, Observation, Sliding Window, Basics of Greedy Algorithms
Problem

Bob has an array A of size N, and he is very fond of two integers X and Y. Find the length of the longest subarray, such that it contains exactly X distinct integers and Y exist at least once in the subarray.

Input format

  • The first line contains an integer T, which denotes the number of test cases.
  • The first line of each test case contains three space separated integers NXY denoting the size of array A, the value of X and Y, respectively.
  • The second line of each test case contains N space-separated integers, denoting the elements of array A.

Output format

For each test case, print the length of the largest subarray, such that it contains exactly X distinct integers and Y exist at least once in the subarray in a new line.

Constraints

1T101N1050A[i]1051X,Y105

 

Sample Input
2
3 2 1
2 3 1
1 1 2
1
Sample Output
2
0
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For test case 1: There exists only one subarray having exactly 2 distinct elements and having at least one occurrence of 1, i.e. [3,1] of length 2. Therefore, the answer will be 2.

For test case 22 is not present in the whole array A. So, the answer is 0.

Editor Image

?