BasicsConditional ProbabilityGoogleMetaJane Street
Problem
Given contingency counts count_a_and_b (both A and B occurred) and count_not_a_and_b (B occurred without A), implement conditional_from_counts(count_a_and_b, count_not_a_and_b) returning P(A∣B)=count(B)count(A∩B).
Why It Matters: Conditioning shrinks the sample space to only the rows where B happened—the exact calculation behind precision, positive predictive value, and funnel conversion.
Function Signature
def conditional_from_counts(count_a_and_b: int, count_not_a_and_b: int) -> float:
Sample Input & Output
Example 1: Medical Test Precision
Input:
count_a_and_b = 30, count_not_a_and_b = 70
Expected Output:
0.3
Explanation: Out of 30 + 70 = 100 positive tests, 30 truly have condition A, so P(A∣B)=0.3.
Example 2: Zero False Positives
Input:
count_a_and_b = 25, count_not_a_and_b = 0
Expected Output:
1.0
Explanation: Every single B event also has A, giving 25 / 25 = 1.0.
Constraints & Edge Cases
- Return
floatconditional probability. - Denominator is
count_a_and_b + count_not_a_and_b > 0. - Return a Python
floatin[0.0, 1.0].
Constraints & Evaluation Criteria
- Return `float` conditional probability.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
20, 60
Expected Output / Criteria
0.25