Bayes' Theorem

MediumProbabilityMath

Description

Given the prior probability P(A), the likelihood P(B|A), and the likelihood P(B|not A), return the posterior probability P(A|B) using Bayes’ theorem. The total evidence is P(B) = P(A)P(B|A) + (1 - P(A))P(B|not A). Round the result to 4 decimal places.

Examples

Input:0.01, 0.9, 0.05
Output:0.1538
Explanation:

Bayes’ theorem scales the prior by how strongly the evidence supports it, divided by every way that evidence could arise.

Input:0.5, 0.9, 0.1
Output:0.9
Explanation:

Bayes’ theorem scales the prior by how strongly the evidence supports it, divided by every way that evidence could arise.

Input:0.1, 0.8, 0.2
Output:0.3077
Explanation:

Bayes’ theorem scales the prior by how strongly the evidence supports it, divided by every way that evidence could arise.

Constraints

  • 0 ≤ each probability ≤ 1
  • P(B) > 0

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.