← All problemsSign in

Expected move

CodeChefRating 1541Open on judge ↗

You are given a fair coin and two integers $X$ and $N$. You repeatedly flip the coin and perform the following operation based on the result: - If it lands on heads, then $X$ will **increase** by $1$. However, if $X = N$ then $X$ will **not** change. - If it lands on tails, $X$ will **decrease** by $1$. You stop as soon as the value of $X$ becomes $1$. Find the expected number of coin flips. N

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