← All problemsSign in

Martingale

You are playing a game called _Martingale_. The rules of the game are as follows: 1. At the beginning of the game, you are given $N$ as input. 2. Set $V = N$, and set $X = 1$. 3. Flip a fair coin. - If the coin lands on heads: Increase $V$ by $X$, and then set $X = 1$. - If the coin lands on tails: Decrease $V$ by $X$, and then set $X = 2X$. 4. If $V \leq 0$ or $V \geq 2N$: - End the gam

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start