Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-121

Second Moment Bound

Problem

The second moment method bounds the probability that a nonnegative integer variable is zero:

P(X = 0) <= Var(X) / E[X]^2.

Return the bound capped at 1.0, and 1.0 when the mean is nonpositive.

Hint

A small relative variance forces the variable to be positive.

Test cases

case 1
in: [10,5]
expected: 0.05
case 2
in: [2,3]
expected: 0.75
case 3
in: [5,25]
expected: 1
case 4
in: [0,1]
expected: 1
Starter codePython
def second_moment_bound(mean, variance):
    # Your code here
    pass

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