https://leetcode.com/problems/guess-number-higher-or-lower-ii/#/description.
We are playing the Guess Game. The game is as follows:
I pick a number from 1 to n. You have to guess which number I picked.
Every time you guess wrong, I'll tell you whether the number I picked is higher or lower.
However, when you guess a particular number x, and you guess wrong, you pay $x. You win the game when you guess the number I picked.
Given a particular n ≥ 1, find out how much money (at minimum) that you need to have to guarantee a win.
I was practicing this problem. I thought this problem can be solved using binary search. In particular, for the worst case, the number can always be assumed located at the right-half of each split.
Example: say n=5. Then you have
[1, 2, 3, 4, 5].
First try= 3, Then second try = 4. This will give you a worst case of 7 dollars. But I have looked at the solutions, it seems to me that they all use dynamic programming. I am wondering how come the binary search algorithm doesn't work in this case?