Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-372

Variance from Second Moment

Problem

The variance equals the second moment minus the squared mean: Var(X) = E[X^2] - (E[X])^2.

Given the second moment and the mean, return the variance.

Hint

Center the second moment on the mean.

Test cases

case 1
in: [2,1]
expected: 1
case 2
in: [5,2]
expected: 1
case 3
in: [0,0]
expected: 0
Starter codePython
def variance_from_second_moment(second_moment, mean):
    # Your code here
    pass

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