BasicsInclusion-ExclusionGoogleMetaJane Street
Problem
Implement union_prob(p_a, p_b, p_a_and_b) returning P(A∪B)=P(A)+P(B)−P(A∩B) via the Inclusion-Exclusion Principle.
Why It Matters: Subtracting the overlap P(A∩B) prevents double-counting users who qualify for both segments (e.g., mobile users AND paid subscribers).
Function Signature
def union_prob(p_a: float, p_b: float, p_a_and_b: float) -> float:
Sample Input & Output
Example 1: Overlapping Events
Input:
p_a = 0.5, p_b = 0.4, p_a_and_b = 0.2
Expected Output:
0.7
Explanation: 0.5 + 0.4 - 0.2 = 0.7.
Example 2: Mutually Exclusive Events (Zero Overlap)
Input:
p_a = 0.25, p_b = 0.35, p_a_and_b = 0.0
Expected Output:
0.6
Explanation: With zero intersection, union simplifies to 0.25 + 0.35 = 0.6.
Constraints & Edge Cases
- Return a float in
[0, 1]. - Handles both overlapping events (
p_a_and_b > 0) and disjoint events (p_a_and_b = 0). - Return a Python
float.
Constraints & Evaluation Criteria
- Return a float in `[0, 1]`.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
0.5, 0.4, 0.2
Expected Output / Criteria
0.7