BasicsExpectationGoogleMetaJane Street
Problem
Implement expected_value(values, probs) returning the expected value E[X]=∑ixipi of a discrete random variable as a Python float.
Why It Matters: Expected value drives decision theory, reinforcement learning Q-values, insurance pricing, and A/B test revenue projections.
Function Signature
def expected_value(values: list[float], probs: list[float]) -> float:
Sample Input & Output
Example 1: Fair 6-Sided Die
Input:
values = [1, 2, 3, 4, 5, 6], probs = [1/6, 1/6, 1/6, 1/6, 1/6, 1/6]
Expected Output:
3.5
Explanation: Average roll is (1+2+3+4+5+6) / 6 = 3.5.
Example 2: Asymmetric Game With Loss
Input:
values = [-10.0, 30.0], probs = [0.75, 0.25]
Expected Output:
0.0
Explanation: -10 * 0.75 + 30 * 0.25 = -7.5 + 7.5 = 0.0 (a fair zero-EV game).
Constraints & Edge Cases
- Return
E[X]as a float. valuesandprobshave equal length andsum(probs) == 1.0.- Works with negative payoffs (losses) as well as positive rewards.
Constraints & Evaluation Criteria
- Return `E[X]` as a float.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[1..6], [1/6..]
Expected Output / Criteria
3.5