Skip to content
DeepForgeby svx
All problems
EasyProbabilitypr-358

Discrete Uniform Mean and Variance

Problem

For the discrete uniform distribution on {1, ..., n}, mean = (n + 1) / 2 and variance = (n^2 - 1) / 12.

Given n >= 1, return [mean, variance].

Hint

The variance grows quadratically with the range.

Test cases

case 1
in: [6]
expected: [3.5,2.9166666666666665]
case 2
in: [1]
expected: [1,0]
case 3
in: [100]
expected: [50.5,833.25]
Starter codePython
def discrete_uniform_mean_and_variance(n):
    # Your code here
    pass

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