Home Interview Probability Problems for Interviews — Solved with Clear Logic

Probability Problems for Interviews — Solved with Clear Logic

In Plain English 🔥
Imagine you have a bag with 3 red marbles and 2 blue marbles. Probability is just your way of answering: 'If I grab one without looking, how likely is it to be red?' You count the outcomes you WANT, divide by ALL possible outcomes, and that fraction is your probability. Every casino game, weather forecast, and spam filter runs on exactly this idea — just with more marbles.
⚡ Quick Answer
Imagine you have a bag with 3 red marbles and 2 blue marbles. Probability is just your way of answering: 'If I grab one without looking, how likely is it to be red?' You count the outcomes you WANT, divide by ALL possible outcomes, and that fraction is your probability. Every casino game, weather forecast, and spam filter runs on exactly this idea — just with more marbles.

Probability questions show up in almost every tech and finance aptitude round — not because companies want mathematicians, but because these problems reveal how you reason under uncertainty. When an interviewer asks 'what are the odds of drawing two aces from a shuffled deck?', they're watching whether you break a problem into smaller pieces, whether you remember to account for replacement vs. no-replacement, and whether you catch your own errors. These are the same mental habits that make a good engineer.

The frustrating part is that most candidates memorise formulas without understanding the logic behind them. So when a question is slightly rephrased — a bag becomes a box, marbles become cards — they freeze. The formula didn't break; their mental model was never solid in the first place. This article fixes that by building probability from the ground up: what it means, why the rules are what they are, and when each rule applies.

By the end of this article you'll be able to set up any classic probability problem from scratch without hunting for the right formula, spot the three most common traps that cost candidates marks, and explain your reasoning out loud — which is exactly what interviewers are listening for.

The Foundation: What Probability Actually Means (and Why It's a Fraction)

Probability is a number between 0 and 1 that measures how likely an event is. A probability of 0 means impossible. A probability of 1 means certain. Everything else lives in between.

The core formula is: P(Event) = (Number of favourable outcomes) / (Total number of equally likely outcomes).

The word 'equally likely' is doing serious heavy lifting there. If you roll a fair six-sided die, each face has the same chance — that's what makes the formula valid. If the die were weighted, the formula breaks immediately. Always ask: are my outcomes truly equally likely?

There are two fundamental rules everything else builds on. The Addition Rule handles OR situations: if you want event A or event B, you add their probabilities but subtract any overlap to avoid double-counting. The Multiplication Rule handles AND situations: if you want event A and then event B, you multiply — but only if the events are independent of each other. Understanding when to add and when to multiply is the single biggest skill in aptitude probability.

basic_probability_foundation.py · PYTHON
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
# === Basic Probability: Die Roll and Coin Toss Examples ===
# Run this to see the core formula in action with real numbers.

def probability(favourable_outcomes, total_outcomes):
    """Returns probability as a decimal and a readable fraction string."""
    if total_outcomes == 0:
        raise ValueError("Total outcomes cannot be zero — that's not a valid sample space.")
    prob = favourable_outcomes / total_outcomes
    return prob, f"{favourable_outcomes}/{total_outcomes}"

# --- Example 1: Rolling a fair six-sided die ---
# Event: getting an even number (2, 4, or 6)
total_die_faces = 6
even_faces = [2, 4, 6]          # these are our favourable outcomes
favourable_even = len(even_faces)

prob_decimal, prob_fraction = probability(favourable_even, total_die_faces)
print(f"P(rolling an even number) = {prob_fraction} = {prob_decimal:.4f}")

# --- Example 2: Drawing a card — Addition Rule (OR) ---
# Event: drawing a King OR a Heart from a standard 52-card deck
# Kings: 4 cards. Hearts: 13 cards. BUT King of Hearts is in both — avoid double-counting!
total_cards = 52
kings = 4
hearts = 13
king_of_hearts = 1              # the overlap between the two groups

# P(King OR Heart) = P(King) + P(Heart) - P(King AND Heart)
favourable_king_or_heart = kings + hearts - king_of_hearts  # = 16
prob_king_or_heart = favourable_king_or_heart / total_cards
print(f"\nP(King OR Heart) = {favourable_king_or_heart}/{total_cards} = {prob_king_or_heart:.4f}")

# --- Example 3: Tossing two fair coins — Multiplication Rule (AND) ---
# Event: getting Heads on both coins
# The coins are independent — first coin result does NOT affect the second
p_heads_coin1 = 1 / 2          # P(Heads) on a fair coin
p_heads_coin2 = 1 / 2          # same, independent event

p_both_heads = p_heads_coin1 * p_heads_coin2   # multiply because AND + independent
print(f"\nP(Heads AND Heads) = 1/2 × 1/2 = {p_both_heads:.4f}")

# Sanity check: list every possible outcome
all_outcomes = [(c1, c2) for c1 in ['H', 'T'] for c2 in ['H', 'T']]
favourable = [o for o in all_outcomes if o == ('H', 'H')]
print(f"All outcomes: {all_outcomes}")
print(f"Favourable outcomes: {favourable}")
print(f"P(HH) by counting = {len(favourable)}/{len(all_outcomes)} = {len(favourable)/len(all_outcomes):.4f}")
▶ Output
P(rolling an even number) = 3/6 = 0.5000

P(King OR Heart) = 16/52 = 0.3077

P(Heads AND Heads) = 1/2 × 1/2 = 0.2500
All outcomes: [('H', 'H'), ('H', 'T'), ('T', 'H'), ('T', 'T')]
Favourable outcomes: [('H', 'H')]
P(HH) by counting = 1/4 = 0.2500
⚠️
Pro Tip: Always enumerate small sample spacesFor any problem with fewer than ~20 total outcomes, list every single possibility before applying a formula. It takes 30 seconds and instantly confirms whether your formula gave the right answer. Interviewers love candidates who sanity-check their own work.

Replacement vs. No Replacement — The Question That Trips Everyone Up

Here's the single most common source of wrong answers in probability aptitude questions: forgetting whether the item goes back into the pool after each draw.

With replacement, every draw is independent. You draw a card, note it, put it back, shuffle. The deck is always 52 cards. The second draw has no memory of the first.

Without replacement, the draws are dependent. You draw a card and keep it. Now the deck has 51 cards — and crucially, the composition of the deck has changed. The probability for the second draw must be recalculated based on what's left.

This is called conditional probability. The probability of event B given that event A has already happened is written P(B | A), pronounced 'P of B given A'. The multiplication rule for dependent events becomes: P(A and B) = P(A) × P(B | A).

A classic interview question: 'What's the probability of drawing two Aces in a row from a shuffled deck, without replacement?' The answer is (4/52) × (3/51) — four aces available first, then only three aces left in a 51-card deck. Getting this right immediately shows the interviewer you understand dependency.

replacement_vs_no_replacement.py · PYTHON
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
# === Replacement vs No-Replacement: Cards and Marbles ===

import math

# --- Scenario: Drawing 2 Aces from a 52-card deck ---

# WITH REPLACEMENT: deck is reset after each draw — draws are independent
p_first_ace_with = 4 / 52       # 4 aces in 52 cards
p_second_ace_with = 4 / 52     # deck is restored — still 4 aces in 52
p_two_aces_with_replacement = p_first_ace_with * p_second_ace_with
print("=== WITH REPLACEMENT ===")
print(f"P(1st Ace)  = 4/52 = {p_first_ace_with:.6f}")
print(f"P(2nd Ace)  = 4/52 = {p_second_ace_with:.6f}  (deck unchanged)")
print(f"P(Two Aces) = {p_two_aces_with_replacement:.6f}")

print()

# WITHOUT REPLACEMENT: first ace is removed — second draw sees 51 cards, 3 aces
p_first_ace_without = 4 / 52   # 4 aces in 52 cards
p_second_ace_without = 3 / 51  # 3 aces remain in 51 remaining cards — KEY CHANGE
p_two_aces_no_replacement = p_first_ace_without * p_second_ace_without
print("=== WITHOUT REPLACEMENT ===")
print(f"P(1st Ace)         = 4/52 = {p_first_ace_without:.6f}")
print(f"P(2nd Ace | 1st was Ace) = 3/51 = {p_second_ace_without:.6f}  (deck shrinks!)")
print(f"P(Two Aces)        = {p_two_aces_no_replacement:.6f}")

print()
print(f"Difference between methods: {abs(p_two_aces_with_replacement - p_two_aces_no_replacement):.6f}")
print("(Ignoring replacement makes you ~14% over-confident in this case)")

print()
# --- Marble Bag Problem (classic aptitude style) ---
# Bag contains: 5 red, 3 blue, 2 green marbles (10 total)
# Q: P(drawing red then blue) WITHOUT replacement?

total_marbles = 10
red_marbles = 5
blue_marbles = 3

p_red_first = red_marbles / total_marbles          # 5/10
p_blue_second_given_red = blue_marbles / (total_marbles - 1)  # 3/9 — one red is gone

p_red_then_blue = p_red_first * p_blue_second_given_red
print("=== MARBLE BAG (No Replacement) ===")
print(f"P(Red first)          = {red_marbles}/{total_marbles} = {p_red_first:.4f}")
print(f"P(Blue second | Red)  = {blue_marbles}/{total_marbles-1} = {p_blue_second_given_red:.4f}")
print(f"P(Red then Blue)      = {p_red_then_blue:.4f}")
print(f"As a fraction         = {red_marbles*blue_marbles}/{total_marbles*(total_marbles-1)} = {red_marbles*blue_marbles}/90")
▶ Output
=== WITH REPLACEMENT ===
P(1st Ace) = 4/52 = 0.076923
P(2nd Ace) = 4/52 = 0.076923 (deck unchanged)
P(Two Aces) = 0.005917

=== WITHOUT REPLACEMENT ===
P(1st Ace) = 4/52 = 0.076923
P(2nd Ace | 1st was Ace) = 3/51 = 0.058824 (deck shrinks!)
P(Two Aces) = 0.004525

Difference between methods: 0.001392
(Ignoring replacement makes you ~14% over-confident in this case)

=== MARBLE BAG (No Replacement) ===
P(Red first) = 5/10 = 0.5000
P(Blue second | Red) = 3/9 = 0.3333
P(Red then Blue) = 0.1667
As a fraction = 15/90 = 15/90
⚠️
Watch Out: The 'restored deck' assumptionUnless a problem explicitly says 'with replacement' or 'the card is put back', always assume no replacement. Real-world draws — lottery balls, cards dealt in poker, hiring from a candidate pool — are almost always without replacement. Assuming independence when there's actually dependence is the #1 error in aptitude exams.

Combinatorics + Probability: Solving 'At Least One' and Multi-Event Problems

Once you're comfortable with single events, interviewers escalate to multi-event problems. The phrasing 'at least one' is a classic escalation — and it has a beautiful shortcut.

Calculating P(at least one success) directly means adding up many cases: exactly one, exactly two, exactly three... It's tedious. Instead, use the complement: P(at least one) = 1 - P(none at all). It's almost always faster.

Combinations (nCr) come into play when order doesn't matter — like choosing a committee from a group, or finding the probability that a hand of cards contains exactly two hearts. The formula nCr = n! / (r! × (n-r)!) counts the number of ways to choose r items from n without caring about order.

The key decision tree is: Does order matter? If yes, use permutations. If no, use combinations. For most probability problems involving draws or selections, order doesn't matter — you're choosing a group, not arranging a sequence. When you combine nCr with the core probability formula, you can solve the most complex-looking aptitude problems in four clean steps: count favourable combinations, count total combinations, divide, simplify.

combinatorics_probability.py · PYTHON
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
# === Combinatorics in Probability: At-Least-One and Multi-Event Problems ===

import math

def combinations(n, r):
    """nCr — number of ways to choose r items from n (order doesn't matter)"""
    return math.comb(n, r)   # Python 3.8+ has this built-in

# ---------------------------------------------------------------
# PROBLEM 1: "At Least One" — Use the Complement Trick
# ---------------------------------------------------------------
# Q: A bag has 4 red and 6 blue marbles. Draw 3 without replacement.
#    What's P(at least one red marble)?

total_marbles = 10
red = 4
blue = 6
draw = 3

# Total ways to draw 3 from 10
total_ways = combinations(total_marbles, draw)   # 10C3 = 120

# P(at least one red) = 1 - P(NO red at all)
# 'No red' means all 3 are blue — choose 3 from 6 blue marbles
all_blue_ways = combinations(blue, draw)          # 6C3 = 20

p_no_red = all_blue_ways / total_ways
p_at_least_one_red = 1 - p_no_red               # the complement shortcut

print("=== PROBLEM 1: At Least One Red ===")
print(f"Total ways to draw 3 from 10 : 10C3 = {total_ways}")
print(f"Ways to draw 3 all-blue      : 6C3  = {all_blue_ways}")
print(f"P(no red)                    = {all_blue_ways}/{total_ways} = {p_no_red:.4f}")
print(f"P(at least one red)          = 1 - {p_no_red:.4f} = {p_at_least_one_red:.4f}")

print()

# ---------------------------------------------------------------
# PROBLEM 2: Exactly K Successes — Combinations in Numerator
# ---------------------------------------------------------------
# Q: From a group of 7 men and 5 women, a committee of 4 is formed randomly.
#    What's P(exactly 2 men and 2 women on the committee)?

total_people = 12   # 7 men + 5 women
men = 7
women = 5
committee_size = 4

# Total ways to form a committee of 4 from 12 people
total_committees = combinations(total_people, committee_size)   # 12C4 = 495

# Favourable: choose exactly 2 men from 7 AND exactly 2 women from 5
# These are independent choices for the two sub-groups
ways_to_pick_2_men   = combinations(men, 2)     # 7C2 = 21
ways_to_pick_2_women = combinations(women, 2)   # 5C2 = 10
favourable_committees = ways_to_pick_2_men * ways_to_pick_2_women  # 210

p_exactly_2_and_2 = favourable_committees / total_committees
print("=== PROBLEM 2: Exactly 2 Men and 2 Women ===")
print(f"Total committee arrangements : 12C4 = {total_committees}")
print(f"Ways to pick 2 men from 7    : 7C2  = {ways_to_pick_2_men}")
print(f"Ways to pick 2 women from 5  : 5C2  = {ways_to_pick_2_women}")
print(f"Favourable arrangements      : {ways_to_pick_2_men} × {ways_to_pick_2_women} = {favourable_committees}")
print(f"P(exactly 2 men, 2 women)    = {favourable_committees}/{total_committees} = {p_exactly_2_and_2:.4f}")

print()

# ---------------------------------------------------------------
# PROBLEM 3: Independent Repeated Trials — Coin Flipped 5 Times
# ---------------------------------------------------------------
# Q: What's P(getting exactly 3 Heads in 5 fair coin flips)?
# This is a Binomial scenario: n=5 trials, k=3 successes, p=0.5

n_flips = 5
k_heads = 3
p_head = 0.5
p_tail = 1 - p_head

# Ways to arrange 3 heads in 5 flips: 5C3
arrangements = combinations(n_flips, k_heads)   # = 10
p_exactly_3_heads = arrangements * (p_head ** k_heads) * (p_tail ** (n_flips - k_heads))

print("=== PROBLEM 3: Exactly 3 Heads in 5 Flips ===")
print(f"Arrangements of 3H in 5 flips: 5C3 = {arrangements}")
print(f"P(H)^3 = {p_head}^3 = {p_head**k_heads}")
print(f"P(T)^2 = {p_tail}^2 = {p_tail**(n_flips-k_heads)}")
print(f"P(exactly 3 Heads) = {arrangements} × {p_head**k_heads} × {p_tail**2} = {p_exactly_3_heads:.4f}")
▶ Output
=== PROBLEM 1: At Least One Red ===
Total ways to draw 3 from 10 : 10C3 = 120
Ways to draw 3 all-blue : 6C3 = 20
P(no red) = 20/120 = 0.1667
P(at least one red) = 1 - 0.1667 = 0.8333

=== PROBLEM 2: Exactly 2 Men and 2 Women ===
Total committee arrangements : 12C4 = 495
Ways to pick 2 men from 7 : 7C2 = 21
Ways to pick 2 women from 5 : 5C2 = 10
Favourable arrangements : 21 × 10 = 210
P(exactly 2 men, 2 women) = 210/495 = 0.4242

=== PROBLEM 3: Exactly 3 Heads in 5 Flips ===
Arrangements of 3H in 5 flips: 5C3 = 10
P(H)^3 = 0.5^3 = 0.125
P(T)^2 = 0.5^2 = 0.25
P(exactly 3 Heads) = 10 × 0.125 × 0.25 = 0.3125
🔥
Interview Gold: The Complement Trick saves you every timeWhenever you see 'at least one', 'at least two', or 'one or more' in a problem, immediately flip to the complement. P(at least one) = 1 - P(zero). This turns a multi-case addition problem into a single clean calculation. Interviewers watch for this — it signals mathematical maturity.
ScenarioRule to UseFormulaExample
Event A OR Event B (mutually exclusive)Addition Rule — no overlapP(A) + P(B)P(roll 1 or roll 2) = 1/6 + 1/6 = 1/3
Event A OR Event B (can overlap)Addition Rule — subtract overlapP(A) + P(B) − P(A∩B)P(King or Heart) = 4/52 + 13/52 − 1/52
Event A AND Event B (independent)Multiplication Rule — independentP(A) × P(B)P(H then H) = 1/2 × 1/2 = 1/4
Event A AND Event B (dependent)Multiplication Rule — conditionalP(A) × P(B|A)P(Ace then Ace, no replace) = 4/52 × 3/51
Selecting a group, order doesn't matterCombinations (nCr)n! / (r! × (n−r)!)3 people from 10: 10C3 = 120 ways
At least one success in multiple drawsComplement Method1 − P(zero successes)P(at least 1 red) = 1 − P(all blue)
Exactly k successes in n independent trialsBinomial FormulanCk × p^k × (1−p)^(n−k)Exactly 3H in 5 flips = 10 × 0.125 × 0.25

🎯 Key Takeaways

  • The core formula — favourable outcomes divided by total equally likely outcomes — is the single idea every probability rule derives from. If you forget a formula, come back to this and count.
  • OR means add (then subtract overlap). AND means multiply (but adjust for dependency if there's no replacement). Confusing these two is the root cause of most wrong answers.
  • The complement trick — P(at least one) = 1 − P(none) — converts the hardest-looking problems into one-step calculations. Reach for it whenever you see 'at least one' or 'one or more'.
  • Always clarify replacement before solving. With replacement → independent events → multiply raw probabilities. Without replacement → dependent events → reduce numerator AND denominator after each draw.

⚠ Common Mistakes to Avoid

  • Mistake 1: Forgetting to subtract the overlap in OR problems — If you just add P(King) + P(Heart) = 4/52 + 13/52 = 17/52, you've counted the King of Hearts twice. The symptom is an answer slightly too high. Fix: always ask 'can both events happen to the same outcome?' If yes, subtract P(A AND B) from your total.
  • Mistake 2: Assuming draws are independent when there's no replacement — Using P(A) × P(B) when it should be P(A) × P(B|A) makes your probability too high. The symptom is the denominator staying constant (e.g., always dividing by 52 instead of 51, then 50). Fix: after each draw, mentally reduce both the numerator (remaining favourable items) and denominator (remaining total items) before multiplying.
  • Mistake 3: Using permutations (order matters) when combinations (order doesn't matter) is correct — If you calculate the number of ways to form a 3-person team from 10 people using 10×9×8 instead of 10C3=120, you overcount by a factor of 3! = 6. The symptom is an answer exactly 6× too small when expressed as a probability. Fix: ask 'does swapping two chosen items create a different outcome?' For committees, hands of cards, and groups — it doesn't. Use nCr.

Interview Questions on This Topic

  • QA bag has 5 red and 3 green balls. Two balls are drawn without replacement. What is the probability that both balls are red? Walk me through your reasoning step by step.
  • QWhat is the probability of getting at least one six when rolling two fair dice? How would your approach change if I said 'exactly one six'?
  • QThree people each independently try to solve a problem. Their individual success probabilities are 1/2, 1/3, and 1/4. What's the probability that the problem gets solved? (Tricky follow-up: what if I asked for the probability that exactly one person solves it?)

Frequently Asked Questions

What is the difference between mutually exclusive and independent events?

Mutually exclusive means the two events cannot happen at the same time — rolling a 1 and rolling a 2 on a single die. Independent means one event doesn't affect the probability of the other — flipping a coin and rolling a die. Crucially, mutually exclusive events are NOT independent: if A happens, B definitely can't, so knowing A completely changes B's probability.

When do I use combinations vs permutations in probability problems?

Use combinations (nCr) when selecting a group where order doesn't matter — a committee, a hand of cards, a lottery ticket. Use permutations (nPr) when the arrangement itself matters — a ranked podium, a password, a sequence of draws where first and second positions are different outcomes. Most aptitude probability questions involving selections use combinations.

How do I know whether to add or multiply probabilities?

Add probabilities when the question involves OR — you want event A or event B to happen. Multiply when the question involves AND — you want event A to happen and then event B to happen. A quick mental test: replace the connecting word with its symbol. 'Or' → + (then subtract overlap if events share outcomes). 'And' → × (then use conditional probability if draws are without replacement).

🔥
TheCodeForge Editorial Team Verified Author

Written and reviewed by senior developers with real-world experience across enterprise, startup and open-source projects. Every article on TheCodeForge is written to be clear, accurate and genuinely useful — not just SEO filler.

← PreviousTime Speed Distance ProblemsNext →Logical Reasoning Patterns
Forged with 🔥 at TheCodeForge.io — Where Developers Are Forged