Guess The Hidden Number Problem Statement
You are given an integer N
and there is a hidden number within the range [0, N] that you must guess. You have access to a function higherLower(k)
which helps in guessing the number. This function returns -1, 0, or 1 based on whether k
is smaller, equal, or greater than the hidden number, respectively.
Example:
Input:
N = 20, hidden number is 8 (you won't have direct access to the hidden number)
Output:
8
Input:
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.
Output:
For each test case, print a single integer representing the hidden number.
Print a separate line for each test case.
Constraints:
1 <= T <= 10
1 <= N <= 10^9
1 <= hidden number <= N
- Time Limit: 1 sec
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.

AnswerBot
4mo
The task is to guess a hidden number within a given range using a function that provides hints about the number's relation to a given input.
Use the higherLower(k) function to determine if the hidden n...read more
Help your peers!
Add answer anonymously...
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

