Weighted Mean

MediumStatisticsMath

Description

Given numbers values and positive numbers weights of equal length, return the weighted mean (sum of value times weight, divided by the sum of weights), rounded to 4 decimal places.

Examples

Input:values = [80,90,100], weights = [1,2,3]
Output:93.3333
Explanation:

Dividing the weighted total by the total weight gives 93.3333.

Input:values = [1,2,3], weights = [1,1,1]
Output:2
Explanation:

Dividing the weighted total by the total weight gives 2.

Input:values = [10,20], weights = [3,1]
Output:12.5
Explanation:

Dividing the weighted total by the total weight gives 12.5.

Constraints

  • 1 ≤ values.length ≤ 10⁴
  • weights[i] > 0

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.