Bayesian Posterior From Error Rates
Updated
Problem statement
A binary condition has prevalence priorPercent among the population. A test has a falsePositivePercent chance of returning positive when the condition is absent, and a falseNegativePercent chance of returning negative when the condition is present. A randomly selected person tests positive.
Compute the probability that the person has the condition given this positive result. Return that probability exactly as an integer array [numerator, denominator] in lowest terms, with a positive denominator. For example, a posterior of one half is [1,2]. All rates are integer percentages.
Function
posteriorAfterPositive(priorPercent: int, falsePositivePercent: int, falseNegativePercent: int) → int[]Examples
Example 1
priorPercent = 1falsePositivePercent = 1falseNegativePercent = 0return = [100,199]A rare condition with one percent false positives has a posterior just above one half after a positive result.
Example 2
priorPercent = 10falsePositivePercent = 5falseNegativePercent = 20return = [16,25]Of the positive tests in a 10,000-person cohort, 800 are true positives and 450 are false positives.
Example 3
priorPercent = 50falsePositivePercent = 0falseNegativePercent = 25return = [1,1]With no false positives, every observed positive comes from an affected person.
Constraints
1 <= priorPercent <= 99.0 <= falsePositivePercent <= 100.0 <= falseNegativePercent <= 99.- The probability of a positive result is nonzero under these bounds.
More Microsoft Phone Screen questions
- Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
- Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
- Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
- Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
- 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
- Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
- Most Visited String SectorsPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Monthly Calendar with Custom Week StartStripe · PHONE SCREENStripe interview questions
- Fractional Share Inventory FlatteningRobinhood · PHONE SCREEN · ONSITE INTERVIEWRobinhood interview questions
- Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
- Evenly Schedule Vehicle InspectionsAmazon · PHONE SCREEN
- Implement Cross-Entropy LossOpenAI · PHONE SCREENOpenAI interview questions
- Cumulative No-Intercept Regression BetasCitadel · PHONE SCREENCitadel interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Per-Segment SpeedingOnePay · PHONE SCREENOnePay interview questions