27. Law of Total Probability

Medium

When an event can be reached through several separate routes, multiply along each route and add the routes:

P(A)=i=1nP(ABi)P(Bi)P(A) = \sum_{i=1}^{n} P(A \mid B_i)\,P(B_i)

Return P(A)P(A). The two lists are aligned and the same length.

solve([0.6, 0.4], [0.02, 0.05])  ->  0.032
# Factory 1 makes 60% with a 2% defect rate; Factory 2 makes 40% at 5%.

Note this is a weighted average, not the plain average of 2% and 5%.

Sign in to write and run your own code.

Implement solve(...)