1 to n. You name numbers one at a time. If you hit the secret, the game is over. If you miss, you pay as many coins as the number you named, and the host tells you whether the secret is higher or lower.
Return the smallest number of coins that guarantees you can keep guessing until you win, no matter which number the host picked. You must never run out of money along the way.n=3 → 2
Guess 2. If that is wrong, the host says "higher" or "lower" and only one number is left. The worst case costs 2.
n=5 → 6
Start with 2: if the number is lower, it is 1 and the total is 2. If higher, 3..5 remain; guess 4, and the worst case is 2 + 4 = 6.
n=1 → 0
n=3
2
Run checks the first 3 tests in your browser. Submit checks all 31 tests on the server, hidden ones included.