Code Room
CodingHard
Question
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.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.