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
4d
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...
Top Nagarro Devops Engineer interview questions & answers
Popular interview questions of Devops Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app