Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-389

Chain Staying in State Probability

Problem

In the chain [[1 - a, a], [b, 1 - b]], the probability of remaining in state 0 for n consecutive steps is (1 - a)^n.

Given a and n, return the stay probability.

Hint

Each step multiplies the probability by the self-transition.

Test cases

case 1
in: [0.1,3]
expected: 0.7290000000000001
case 2
in: [0.5,2]
expected: 0.25
case 3
in: [0,10]
expected: 1
Starter codePython
def chain_staying_in_state_probability(a, n):
    # Your code here
    pass

3 test cases · run your code against them in the editor