Query and Array
Submissions: 579   Accuracy:

9.22%

  Difficulty: Easy   Marks: 2

Given an array of integers A[] and a query integer Q. Find the number X in the array such that it can be converted from Q to X such that F(Q,X) is minimum.

F(A,B)=Number of bits flipped to change the number A to B.

Print X.

If there are more than one values in A[] such that F(Q,X) is minimum print the smallest value of X for  which F(Q,X) is minimum.

Input:
The first line of the test case contains an Integer T denoting number of test case. The first line of each test case contains two integer N and Q denoting the size of the array and the query, the second line contains N space separated integer A[i], where A[i] denotes the ith element of the array.

Output:

Print X.

Constraints:
1<=T<=100
1<=N<=10^3
1<=Q<=10^6
1<=A[i]<=10^6

Example:

Input:
2
9 1
5 32 1 7 10 50 19 21 2
9 8
5 32 10 7 10 50 19 21 2

Output:
1
5

** For More Input/Output Examples Use 'Expected Output' option **

Author: ShivamKD


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.