Problem
A secret number pick has been chosen from 1 to n. You cannot see it, but you are given a function guess(num) that tells you how your guess compares:
- -1 if your guess is too high (pick < num)
- 1 if your guess is too low (pick > num)
- 0 if you got it
Write guess_number(n, guess) (TypeScript: guessNumber(n, guess)) that returns pick. The tests count your calls, so use as few as possible.
Example 1
- Input
- n = 10, pick = 6
- Output
- 6
Example 2
- Input
- n = 1, pick = 1
- Output
- 1
Example 3
- Input
- n = 2, pick = 1
- Output
- 1
Constraints
1 <= n <= 2^31 - 11 <= pick <= n