Gambler's ruin probability
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) → floatExamples
in
[10,5,1,2]out0.5What 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
solution.py
InputExpectedGot
[10,5,1,2]0.5not run yetsample