


You are given ‘N’ = 20, and the hidden number is ‘8’. You won't have access to the hidden number and you will have to guess the number ‘8’ using the higherLower function and print it.
The first line of input contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains two space-separated integers, ‘N’ and the hidden number.
For each test case, print a single integer representing the hidden number.
Print a separate line for each test case.
1 <= T <= 10
1 <= N <= 10^9
1 <= hidden number <= N
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the given function.
In this approach, we will iterate through every number from 1 until higherLower(n) is equal to 0. Then we return ‘n’ where higherLower(n) is 0.
In this approach, we can see that if our guess is less than the hidden number, all the numbers smaller than the guess can’t be the answer. Similarly, if our guess is more than the hidden number all the numbers larger than our guess can’t be the answer so we can binary search our guess on all the numbers from 1 to ‘N’.
Algorithm:
Element Count in Ranges
First Digit One
Minimize Maximum Adjacent Distance
Sorted Doubly Linked List to Balanced BST
Minimized Maximum of Products Distributed to Any Store