374. Guess Number Higher or Lower

Practice Guess Number Higher or Lower for free on NudgeCode: Easy, Binary Search pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

A number pick between 1 and n (inclusive) has been chosen, and you have to find it. You can't see pick. Instead, call the predefined function guess(num), which returns:

Return pick.

Your function only receives n. The tests list pick as an input so you can read each case, but it is not passed to your function. Each test allows at most 32 calls to guess; the 33rd call fails the test.

Example

n = 10, pick = 6  ->  6

Constraints