Code RoomGambler's ruin probability
HardPrep Room Coding #1058

Gambler's ruin probability

CodingAlgorithms & data structuresSenior–Staff~30 min

In the gambler's ruin problem you start with `i` dollars and bet $1 per round; you win a round (gain $1) with probability p = p_num/p_den, else lose $1. You stop at $0 (ruin) or at $N (target). Return the probability of reaching $N before $0, rounded to 6 decimals. Handle both the fair (p=1/2) and biased cases.

Implement
gamblers_ruin_prob(N: int, i: int, p_num: int, p_den: int) → float
Examples
in[10,5,1,2]out0.5
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[10,5,1,2]0.5not run yetsample