Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-146

Expected Fixed Points

Problem

A uniformly random permutation of n items has exactly one fixed point in expectation: each of the n items is fixed with probability 1 / n and expectations add.

Return 1.0 for n >= 1 and 0.0 for n <= 0.

Hint

Use indicator variables for each item being a fixed point.

Test cases

case 1
in: [1]
expected: 1
case 2
in: [10]
expected: 1
case 3
in: [0]
expected: 0
Starter codePython
def expected_fixed_points(n):
    # Your code here
    pass

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