← back to unit
Medium
# searching medium
Guess the Number (Smartly)
The genie thinks of a number between 1 and n, and after each guess says only higher or lower. The smart move: always guess the MIDDLE of what's left. 🧞
You get n and the genie's secret. Play the smart strategy and print every guess you make, separated by spaces, ending with the winning guess.
Example:
Input: n = 100, secret = 73
Output: 50 75 62 68 71 73
Guess the middle of 1–100 (50, too low), then the middle of 51–100 (75, too high), then the middle of 51–74 (62, too low) — narrowing the range each time until landing on 73.
💡 need a hint?
srch-guess-number.py🔒 given lines are locked — write your code in between
loading...