Is it just me or is the question confusing?
I know n. Only if I know the value of the number in that was thought of (or rather for which I pay 0$), I can simulate the amount that can give me a guaranteed win? Secondly, it says "the amount needed for a guaranteed win". It never says minimum?
Why n is 2 the correct answer is $1?????
for worst case I should guess 2 and then pay $2
suppose n == 2 ;
then you will have [1, 2] ;
the first situation
if you guess is 2 , you will have two options given. first , you are correct , second you are wrong .
if you are correct , then pay 0 $, but if you are wrong, then you pay 2$
the worst case for the above is 2$ ;
the second situation
if you guess is 1 , you will still have two options given. first , you are correct , second you are wrong .
if you are correct , then pay 0 $, but if you are wrong, then you pay 1$
the worst case for the second situation is 1$ ;
According to above, the money you have to have is the MIN (worst case for first situation , worst case for second situation) which is 1 $.
make sense ?
@scott Thanks for your detailed explanation.
@ploirliu2 Hi. After some trials, I found the solution. Refer to this post https://discuss.leetcode.com/topic/52627/recursion-memization :)
@ploirliu2 for [1,3], you pick 2, even if it is wrong, you've already known the answer. If higher,it is 3, otherwise, it is 1, you don't need another guess anymore. The worse case for guessing 2 only costs 2. What if I pick 1 or 3 ? Just think about it a little bit, you will definitely get the answer :)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.