Associated Course(s):
Sudo Placement 2019

Given an array of sorted integers. The task is to find the closest value to the given number in array. Array may contain duplicate values.

**Note:** If the difference is same for two values print the value which is greater than the given number.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains two integers N & K and the second line contains N space separated array elements.

**Output:**

For each test case, print the closest number in new line.

**Constraints:**

1<=T<=100

1<=N<=10^{5}

1<=K<=10^{5}

1<=A[i]<=10^{5}

**Example:
Input:**

2

4 4

1 3 6 7

7 4

1 2 3 5 6 8 9

**Output:**

3

5

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.

Login to report an issue on this page.