Code RoomRandom walk absorption
HardPrep Room Coding #1278

Random walk absorption

CodingAlgorithms & data structuresSenior–Staff~30 min

A token starts at position 0 on the number line. Each step it moves +1 with probability p and -1 with probability (1-p), where p is given as a float. Return the probability, rounded to 6 decimal places, that the token reaches position +a before it reaches position -b (a and b are positive integers; the walk is absorbed at +a or -b). Constraints: 1 <= a, b <= 1000, 0.0 < p < 1.0.

Implement
reach_a_before_neg_b(a: int, b: int, p: float) → float
Examples
in[1,1,0.5]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
[1,1,0.5]0.5not run yetsample