Expected Value
MediumProbabilityMathArray
Description
Given an array of outcome values and a parallel array of their probabilities (which sum to 1), return the expected value: the sum of each value multiplied by its probability. Round the result to 4 decimal places.
Examples
Input:
[1,2,3], [0.2,0.3,0.5]Output:
2.3Explanation:
The expected value sums each outcome weighted by the probability that it occurs.
Input:
[10,20], [0.5,0.5]Output:
15Explanation:
The expected value sums each outcome weighted by the probability that it occurs.
Input:
[2,4,6], [0.25,0.25,0.5]Output:
4.5Explanation:
The expected value sums each outcome weighted by the probability that it occurs.
Constraints
- •
1 ≤ length ≤ 10³ - •
probabilities sum to 1