Sample Variance

MediumStatisticsMathArray

Description

Given an array of numbers nums (length ≥ 2), return the sample variance using the (n - 1) denominator, rounded to 4 decimal places.

Examples

Input:nums = [2,4,6,8]
Output:6.6667
Explanation:

Summing squared deviations from the mean and dividing by n minus one gives 6.6667.

Input:nums = [1,2,3,4,5]
Output:2.5
Explanation:

Summing squared deviations from the mean and dividing by n minus one gives 2.5.

Input:nums = [10,10,20]
Output:33.3333
Explanation:

Summing squared deviations from the mean and dividing by n minus one gives 33.3333.

Constraints

  • 2 ≤ nums.length ≤ 10⁴

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.