Code Room
CodingHard
Question
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) → floatExamples
in
[1,1]out1What 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.