Question
Coins are located in boxes, but the content of each box is unknown. A box has a probability $p$ of containing a coin, but a probability $1-p$ of forcing its opener to quit the game (and lose all coins).
What number of boxes $k$ would need to be opened for the largest expected coin gain?
Additional question: If $n$ players play this game, what would be the best number of box openings you should make in order to maximize your winning probability (how many boxes would need to be opened to make the probability of having the most coins greatest), assuming each player opens some random number of boxes, between $0$ and $2k$.
I came up with this problem in my head, and am unsure about my approach to the first part. The second part seems difficult to me, and I don't really have any idea.
Attempt
As for the first problem, I think the coin gain can be written as a random variable which is a sum of indicators, $$X=X_1+X_2+\dots +X_k$$
So the expected coin gain is $$\mathbb{E}[X]=\mathbb{E}[X_1]+\mathbb{E}[X_2]+\dots +\mathbb{E}[X_k]$$
Now, by definition, for each $1\leq i\leq k$, $$\mathbb{E}[X_i]=p^i$$
And therefore we have $$\mathbb{E}[X]=p+p^2+\dots +p^k = \frac{p(p^k-1)}{p-1}$$
We are seeking the $k$ which maximizes this expression. But here something fails, since this is a decreasing function of $k$, making $k=1$ its maximum, which doesn't make sense. I think there is something I am missing in my attempt.
I appreciate solutions and ideas for both questions, as well as help understanding the flaw in my attempt. Thanks.
The geometric distribution being memoryless, the optimal strategy consists of quitting after a fixed number $n$ of tries, which has expected value $np^n$ (since the only two outcomes of the game are "keep your earnings" and "lose everything"). For fixed $p$ this expression is maximised at $n=-\frac1{\ln p}$, but $n$ must be an integer, so the optimal $n$ is whichever gives the higher $np^n$ of $\lfloor n\rfloor$ and $\lceil n\rceil$.