All problems
Expected Largest Spacing
Problem
Place n points independently and uniformly on [0, 1]. The n + 1 spacings including the two end gaps form a Dirichlet(1, ..., 1) vector whose largest component has expectation:
E[max spacing] = H_(n+1) / (n + 1)
where H_m is the m-th harmonic number. Return 0.0 for negative n.
Hint
For a uniform Dirichlet vector with m components the expected maximum is H_m / m.
Test cases
case 1
in: [0]
expected: 1
case 2
in: [1]
expected: 0.75
case 3
in: [2]
expected: 0.611111111111111
case 4
in: [4]
expected: 0.45666666666666667
Starter codePython
def expected_largest_spacing(n):
# Your code here
pass4 test cases · run your code against them in the editor