| Hello 2026 |
|---|
| Finished |
You are given an array $$$a$$$ of length $$$n$$$, and an integer $$$k$$$. Let $$$f(l,r)$$$ be the value of $$$\operatorname{mex}(a_l,a_{l+1},\ldots,a_r)$$$$$$^{\text{∗}}$$$. You want to perform the following operation $$$n-k+1$$$ times:
For example, in the array $$$[1,2,0,1,3,0]$$$ with $$$k=3$$$, the two possible $$$(l,r)$$$ pairs are $$$(1,3)$$$ and $$$(2,4)$$$ (since they each have $$$\operatorname{mex} 3$$$, which is the maximum among all windows of size $$$3$$$). Therefore, you can remove any one of the indices $$$1,2,3,4$$$ in your next move.
After $$$n - k + 1$$$ operations, you will have a sequence of length $$$k-1$$$. Your objective is to maximize the $$$\operatorname{mex}$$$ of the remaining elements. Please output the maximum $$$\operatorname{mex}$$$ possible.
$$$^{\text{∗}}$$$The minimum excluded (MEX) of a collection of integers $$$c_1, c_2, \ldots, c_k$$$ is defined as the smallest non-negative integer $$$x$$$ which does not occur in the collection $$$c$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two positive integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 2 \cdot 10^5$$$).
The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0 \le a_i \le n$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
Output a single non-negative integer representing your answer.
53 30 0 04 20 2 1 35 30 1 2 1 06 20 1 0 1 2 07 50 1 2 4 0 3 1
11214
In the first test case, we can select the interval $$$[1,3]$$$. Then, delete $$$a_2$$$ to obtain $$$[0,0]$$$. The process terminates, and the $$$\operatorname{mex}$$$ of the remaining elements is $$$1$$$.
In the third test case, we can perform the following operations:
| Name |
|---|


