Problem
A game picks a hidden number pick from 1 to n. You must find pick. Your function gets only n. The input also shows pick, so that you can see the full test.
To check a guess, call the API guess(num). It returns -1 if num is larger than pick. It returns 1 if num is smaller than pick. It returns 0 if num is equal to pick.
Return the hidden number pick. Use as few calls to guess as possible.
Example 1
- Input:
- n = 10, pick = 7
- Output:
- 7
- Explanation:
- A guess of 5 returns 1, so
pickis larger than 5. A guess of 8 returns -1, sopickis smaller than 8.
Example 2
- Input:
- n = 1, pick = 1
- Output:
- 1
Example 3
- Input:
- n = 50, pick = 13
- Output:
- 13
Constraints
- 1 <= n <= 2^31 - 1
- 1 <= pick <= n
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Guess Number Higher or Lower II
Coding
- Given an API for lower-level hard disk management, implement APIs for storing, retrieving, and error-correcting data in a higher-level storage device composed of three of the lower-level disks.
Coding
- Guess the Number Using Bitwise Questions I
Coding
- Guess the Number Using Bitwise Questions II
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
OpenAI
Leetcode 374. Guess Number Higher or Lower
Reported Aug 26, 2026 · 1 source report
STAFF
Source snapshot: Nov 12, 2026
View source