You are given an array of \(N\) numbers \(A_1, A_2,\ldots, A_N\). In one operation, you can pick any index \(i\) and change \(A_i \) to \(x (1 \leq x \leq 10^9)\). Given an integer \(K\), find the minimum number of operations required to make \(K\) the mode of the array.
Note: A number is called the mode of the array if it is more frequent than any other number in the array.
Example: The mode of array \([1, 1, 3]\) is \(1\). The array \([1, 1, 3, 3]\) does not have any mode.
Input format
- The first line contains the number of test cases \(T (1 \leq T \leq 1000)\).
- The first line of each test case contains two integers, \(N\) and \(K (1 \leq K \leq 10^9)\) where N denotes the number of elements in the array.
- The second line contains \(N\) integers \(A_1,A_2, \ldots, A_N (1 \leq A_i \leq 10^9)\) denoting the contents of the array.
Note: Sum of \(N\) over all test cases does not exceed \(2 \times 10^5\).
Output format
For each test case output a line containing the minimum number of operations required to make \(K\) the mode of array \(A\).
Constraints
\(1 \leq T \leq 1000\)
\(1 \leq N \leq 2 \times 10^5\)
\(1 \leq K \leq 10^9\)
\(1 \leq A_i \leq 10^9 \)
Sum of \(N\) over all test cases is less than or equal to \(2 \times 10^5\)
For the first case, we can see that \(1\) is already the mode of the array.
For the second case, we can choose index \(3\) and do the operation \(a_3 = 1\). The array will be \([1, 1, 1, 3]\). Now, \(1\) is the mode of the array.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor