BasicsCDFPMFGoogleMetaJane Street
Problem
Given a discrete PMF list pmf, implement pmf_to_cdf(pmf) returning the cumulative distribution list where cdf[i] = sum(pmf[:i + 1]).
Why It Matters: CDFs power inverse-transform sampling, nucleus (top-p) LLM decoding, and tail-probability queries like P(X≤k).
Function Signature
import numpy as np
def pmf_to_cdf(pmf: list[float]) -> list[float]:
Sample Input & Output
Example 1: 4-Outcome Discrete PMF
Input:
pmf = [0.1, 0.2, 0.5, 0.2]
Expected Output:
[0.1, 0.3, 0.8, 1.0]
Explanation: Running cumulative sums are [0.1, 0.3, 0.8, 1.0].
Example 2: Single-Point Distribution
Input:
pmf = [1.0]
Expected Output:
[1.0]
Explanation: A degenerate 1-outcome PMF maps directly to [1.0].
Constraints & Edge Cases
- Return a list of cumulative probabilities ending at
1.0. - The final element of a valid CDF is
1.0(up to floating-point tolerance). - Return a standard Python
list[float].
Constraints & Evaluation Criteria
- Return a list of cumulative probabilities ending at `1.0`.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[0.2, 0.5, 0.3]
Expected Output / Criteria
[0.2, 0.7, 1.0]