Code RoomFrog jump expected time
HardPrep Room Coding #1285

Frog jump expected time

CodingAlgorithms & data structuresSenior–Staff~30 min

A frog starts on stair 0 and wants to reach stair n. From any stair i < n it jumps to i+1 with probability p and stays on i with probability (1-p) (a wasted jump), each jump taking one unit of time. Return the expected number of jumps (time units) to first reach stair n, rounded to 6 decimal places. Constraints: 1 <= n <= 100000, 0.0 < p <= 1.0.

Implement
expected_jumps(n: int, p: float) → float
Examples
in[1,1]out1
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]1not run yetsample