Day 2: Compound Event Probability | 10 Days Of Statistics | HackerRank Solution

Hello coders, today we are going to solve Day 2: Compound Event Probability HackerRank Solution which is a Part of 10 Days of Statistics Series.

Day 2: Compound Event Probability


In this challenge, we practice calculating the probability of a compound event.


There are 3 urns labeled XY, and Z.

  • Urn X contains 4 red balls and 3 black balls.
  • Urn Y contains 5 red balls and 4 black balls.
  • Urn Z contains 4 red balls and 4 black balls.

One ball is drawn from each of the 3 urns. What is the probability that, of the 3 balls drawn, 2 are red and 1 is black?

Solution – Compound Event Probability Solution


# Set data
x = {"Red":4/7, "Black":3/7}
y = {"Red":5/9, "Black":4/9}
z = {"Red":4/8, "Black":4/8}

# Get possibilities
first_possibility = x["Red"] * y["Red"] * z["Black"]
second_possibility = x["Red"] * y["Black"] * z["Red"]
third_possibility = x["Black"] * y["Red"] * z["Red"]

# Get probability
print(first_possibility + second_possibility + third_possibility)

The Correct answer is 17/42.

Disclaimer: The above Problem (Compound Event Probability) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *