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.
Be the first one to answer
Add answer anonymously...
Nagarro Devops Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter