

For the given arr[ ] = { 1, 2, 5, 7, 12, 14 } and X = 10
The floor of 10 is 7 because 7 is the largest element in the array which is smaller than 10.
The first line of input contains an integer ‘T’, denoting the number of test cases. Then each test case follows.
The first line of each test case contains an integer ‘N’ denoting the number of elements in the array.
The second line of each test case contains ‘N’ space-separated integers representing the elements of the array.
The third and the last line of each test case contains an integer representing ‘X’.
For each test case, print a single integer ‘K’ denoting the floor value of ‘X’ in the array. In case, there is no floor value of ’X’ in the array ‘A’, print -1.
The output of each test case will be printed on a separate line.
You do not need to input or print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 5 * 10 ^ 4
0 <= X, A[i] <= 10 ^ 8
Time Limit: 1 sec.
The idea is to iterate from left to right of the array and compare ‘X’ with the elements of the array, while it is smaller than or equal to ‘X’ then update the answer else stop.
Let the function be ‘floorSearch(‘A’, ‘X’, ‘N’)’, which returns the floor of ‘X’ in the array ‘A’ of length ‘N’.
The idea is to use binary search.
Compare the middle element of the current length array
Hence in every step, we reduce the length of the search space.
Let the function be ‘floorSearch(‘A’, ‘X’, ‘N’)’, which returns the floor of ‘X’ in the array ‘A’ of the length of ‘N’.