ML Interview Q Series: Calculating Probability: Two Cards Differing in Color and Number Using Conditional Probability
Browse all the Probability Interview Questions here.
Suppose you have 50 cards, made up of 5 distinct colors with 10 numbered cards (1 through 10) in each color. If two cards are drawn at random from this deck, what is the probability that the two chosen cards differ in both color and number?
Short Compact solution
After drawing the first card, there are 49 cards left. Out of these, 40 belong to a different color than the first one, so the probability that the second card has a different color is 40/49. Then, considering only those 40 possible cards, 36 of them do not share the same number as the first card, giving a conditional probability of 36/40. Multiplying both probabilities yields:
Hence, the final probability that the two drawn cards differ in both color and number is 36/49.
Comprehensive Explanation
To understand this result in depth, begin by noting that the first card drawn can be anything. There are no restrictions on it, so it automatically provides the “reference” color and number. Once that first card is removed, the deck has 49 cards left.
Among these 49 remaining cards, any that share the same color as the first card cannot satisfy the “different color” condition. Because there are 10 cards for each of the 5 colors in the full deck, and you’ve already taken 1 card of a particular color, there are 9 cards left in that color. That means 9 cards out of the 49 do not meet the color criterion. Consequently, 49 − 9 = 40 cards do have a different color from the first card.
Next, only consider those 40 cards of a different color. We now also need them to have a different number. The first card’s specific number was taken out of each color set; in each color category, there are 10 unique numbers, but for one number, we already took the “instance” of that number in the first card’s color. However, when focusing on these 40 cards from the other 4 colors, each of those 4 colors still has all 10 possible numbers except the one that matches the number of the first card. Therefore, for each of those 4 different colors, exactly 9 possible numbers remain that do not match the first card’s number. That gives us 4 × 9 = 36 cards which fulfill both “different color” and “different number.”
The probability of having a different color is therefore 40/49. Given that the second card is among those 40 differently colored cards, the probability that it also differs by number is 36/40. Multiplying these two probabilities gives the final result:
This simplified fraction captures exactly how likely it is that the two drawn cards match neither color nor number.
Why multiply probabilities?
When determining the joint probability of two separate requirements (“the second card is a different color” and “the second card is also a different number”), you use multiplication because you want the probability of both events happening together. These events are handled sequentially: first, we filter out cards that violate the “different color” condition, and then from that subset, we look at the probability that they also differ in number. Thus, we multiply the probability of the second card having a different color by the conditional probability of it having a different number given the different color.
Potential edge cases in card-drawing scenarios
One subtlety to be aware of is that this calculation assumes there is no replacement of the first card back into the deck. If the procedure had been to draw one card and then put it back before drawing the second, the deck composition for the second draw would be the same as initially (50 total cards). In that case, you would need to calculate the probability accordingly using a different approach because the events would be independent in a different sense (full replacement means the second card draw is unaffected by what the first card was).
Additionally, if the deck had a non-uniform distribution of numbers (for example, more than one copy of each number per color, or an unequal distribution of how many cards each color has), the original approach would need to be adjusted to account for those complexities. The core principle is to count how many favorable outcomes remain once the first card is taken out, then divide by the total number of possibilities left.
Follow-Up Questions
How can we verify this probability calculation programmatically?
It’s often helpful to write a short simulation to confirm any combinatorial probability. The core idea is to generate a deck of 50 cards programmatically, randomly draw 2 cards many times, and count how often they differ in color and number. The ratio of successes over total trials should converge to the theoretical probability as the number of trials grows large.
import random
def simulate_draws(num_simulations=1_000_000):
# Create the deck: (color, number)
# Let's label colors as 0..4, numbers as 1..10
deck = [(color, number) for color in range(5) for number in range(1, 11)]
match_count = 0
for _ in range(num_simulations):
# Shuffle or randomly pick two distinct cards
card1, card2 = random.sample(deck, 2)
# Check if color and number differ
if card1[0] != card2[0] and card1[1] != card2[1]:
match_count += 1
return match_count / num_simulations
if __name__ == "__main__":
result = simulate_draws()
print(f"Estimated Probability: {result:.5f}")
If you run the above simulation multiple times, you should see the output converge around 36/49 ≈ 0.73469.
If the question allowed drawing with replacement, how would the answer change?
With replacement, each card is drawn from the full 50-card deck independently. The probability that the second card is a different color would then be the fraction of cards in the deck that have a different color than the first. Since for any single card there are 4 different colors out of 5, that gives a probability 4/5. Independently, the probability that the second card has a different number would be 9/10 (because for each number, there are 9 different numbers out of 10). For two independent events, we would multiply 4/5 by 9/10, yielding 36/50 = 18/25 = 0.72 as the probability.
How does this approach generalize if the deck structure changes?
The overarching method remains:
Remove the first card and note its color and number. Count how many cards remain that differ in color from that first card. Among those remaining, count how many also differ in number. Divide by the total number of remaining cards for the sequential probabilities, then multiply those probabilities.
In a different deck configuration, you just need to adjust how you do the counting. The logic stays the same: find the probability that the second card meets one condition, then multiply by the probability of meeting the second condition given that the first was met.
What if an interviewer asks for a direct combinatorial argument without conditional probabilities?
Pick any color-number pair for the first card. That’s 50 ways. For the second card, there are 4 remaining colors × 9 different numbers = 36 ways that differ in both color and number. So there are 50 × 36 ways, but since order doesn’t matter if you say “choose 2 cards,” you would be double-counting. Dividing by 2 corrects it, giving (50 × 36)/2 = 900 ways.
This direct combinatorial approach might be required if an interviewer wants to see how you handle counting all possible outcomes without relying on step-by-step conditional probability.
How does this probability compare to the probability of matching color or number?
Sometimes an interviewer might then ask you to confirm consistency by computing the complementary probability: that the two cards share at least the same color or the same number. The complement of “differ in both color and number” is “either same color or same number (or both).” The result would be 1 − 36/49 = 13/49. This is a good check to ensure your reasoning is consistent with the total probability space.
These elaborations show that understanding both the step-by-step conditional method and the combinatorial counting approach gives you a robust foundation for explaining why the final probability is 36/49, and how to adapt to variants of the problem.
Below are additional follow-up questions
What if the interviewer wants to consider the order of drawing the two cards and asks about the probability under ordered selection versus unordered selection?
When dealing with probabilities, one crucial subtlety is determining whether we are treating the two-card draw as an ordered process (where the first card drawn matters, and we track “first” vs. “second” explicitly) or an unordered process (where only the combination matters, so the pair {Card A, Card B} is considered the same as {Card B, Card A}).
In the original solution, we effectively treated the process as ordered: we picked the first card, then conditioned on that card when picking the second. Yet, mathematically, if the interviewer explicitly wants to see the probability in the sense of unordered draws (combinations), the final numerical result remains the same. The difference is that with an ordered perspective, we go through a conditional probability chain:
First card can be anything.
Probability(second card differs in color and number) = Probability(different color) × Probability(different number given different color).
When considering combinations (unordered), we instead count the number of favorable 2-card sets and divide by the total number of 2-card sets. In both views, the answer 36/49 is identical.
What if we only cared about the color being different (and we do not care about the numbers at all)?
Suppose a follow-up scenario changes the question to: “What is the probability that two drawn cards are just of different color, regardless of their numbers?”
By conditioning on the first card again, we see that for the second card, there are 50 − 1 = 49 cards left after picking the first. Among these, only 9 cards remain in the same color, and 40 cards are in different colors. Thus, the probability that the two drawn cards differ in color (with no concern about their numbers) is 40/49.
One subtlety might be if the deck had an uneven distribution of colors (for instance, some colors had more cards than others). In that case, the logic would require adjusting the count of remaining cards that still fulfill the “different color” criterion, and we would not end up with a simple 9-per-color leftover.
How do the calculations change if the deck is incomplete or damaged?
Consider a scenario where someone accidentally removed a few random cards from the 50-card deck, but you only know that some unknown subset is missing. This incomplete deck might have an irregular distribution of colors and numbers.
The standard approach for the full deck no longer applies because you do not have exactly 10 cards per color. You also lack the certainty about how many cards share the same number or color.
The correct solution then depends on the specific composition of the remaining deck. You would count the frequency of each color and number in the deck you actually have, then do a conditional probability approach:
Pick one card (any from the incomplete set).
Out of the remaining cards in that set, figure out how many differ by color and by number.
A key subtlety is that you cannot rely on symmetrical arguments like “9 other cards of the same color remain” because that might no longer be true in an incomplete deck. Each color might be missing a different number of cards, and some numbers might be missing entirely.
What if the interviewer presents a deck where each color can appear in multiple “shades” or each number can appear multiple times per color, creating unbalanced groupings?
Another real-world pitfall is a deck that is not uniform, e.g., some color–number pairs appear more frequently than others. If we assume a deck with the same total of 50 cards, but the distribution is skewed (say color 1 has 12 cards, color 2 has 8, etc.), or the numbering system is not 1–10 but repeated in some pattern, the key principle remains:
Count how many ways you can choose two cards that differ in color and number.
Divide that by how many ways you can choose two cards at all.
Mathematically, you must identify exactly how many color–number pairs exist in each color group, then carefully count pairs that satisfy the difference condition. You could do it via a direct combinatorial approach or by sequential probability with adjusted counts.
For example, if color A had 12 cards, color B had 8, color C had 10, color D had 10, color E had 10 (total 50), you cannot rely on the neat ratio of “40 out of 49” for the color difference, because drawing a card from the color that has 12 cards changes the leftover color distribution. Each color leftover might have a different total. Then for the number difference, you also check the specific number frequencies.
The lesson is that uniformity and balanced distribution are what make the original simplified ratio straightforward. Once that uniformity is removed, you must do a direct count or hypergeometric-based approach for each color–number combination.
How could we adapt a hypergeometric distribution perspective, especially if the question extended to more than 2 cards or to partial matching criteria?
The hypergeometric distribution is often used when sampling from a finite population without replacement. Typically, if you want the probability of drawing a certain number of “successes” from a population that contains a known number of “successes,” you use the hypergeometric formula:
N is the total population size (50 in the original problem),
K is the total number of “success” items (the meaning of “success” depends on your framing),
n is how many items we draw without replacement,
k is how many successes we want in those n draws.
For “different color” or “different number,” you might define success or failure in a certain way and use the hypergeometric formula to calculate these probabilities. However, because our question specifically asks that the second card differs from the first, you need a more sophisticated approach—possibly applying hypergeometric distributions multiple times, or combining them with logic for color and number constraints.
For multiple draws, you could try:
First, define the event “all drawn cards differ in color and number from each other.”
Evaluate how many ways to choose a set of n cards all mutually distinct in color and number.
Divide by the total ways to choose any n cards from the deck.
If each color–number pair is unique and there are no duplicates, you can systematically count. But it becomes more complex than a standard single hypergeometric expression if you impose both color and number constraints simultaneously. You might need to combine multiple hypergeometric arguments or use inclusion-exclusion principles for more draws.
How might the solution process change if there was a practical constraint, such as physically drawing the two cards in front of you, and you observe the color but not the number on the first card (or vice versa)?
Imagine a real-world scenario where you only see the color of the first card but not its number (some detail is hidden). Then you’re asked the probability that the second card will not match the color (which you know) and also not match the unknown number.
You do know the color of the first card, so you can exclude those 9 same-color remaining cards out of 49. So you still see that 40 remain in different colors.
However, you do not know the exact number of the first card. Without that knowledge, from your perspective, each of the 10 possible numbers in the first card’s color is equally likely.
In an expected-value sense, you would still get 36 out of those 40 being distinct in number, yielding the same 36/40. But the logic to arrive there might be more subtle, because you are effectively summing over the distribution of unknown numbers. Each possible number of the first card is equally likely, so in expectation, 1 out of 10 possible numbers is excluded in each of the other 4 colors, giving 4 × 9 = 36.
A pitfall here is incorrectly thinking you cannot compute the probability at all because you “don’t know the number.” In reality, from an expected-value perspective, you end up with the same final probability, as each unknown number is equally probable to have been drawn.
How could we systematically check for logical errors or double counting in the probability derivation?
Double counting can occur if you try to mix ordered and unordered reasoning incorrectly or if you attempt to directly count all 2-card outcomes that differ by color and number without carefully adjusting for the symmetry in how pairs are formed.
A systematic checklist:
If using sequential/conditional probability, confirm that at each step the denominator matches the number of remaining cards.
Ensure that the numerator or the set of favorable outcomes only includes cards that meet the required condition.
If using a combinatorial approach, confirm that your division by 2 (or not) correctly accounts for whether order matters.
Compare both approaches (conditional probability vs. counting pairs directly) and verify they match. If they do not match, that’s a red flag for a counting or logic error.
In an interview, an easy way to avoid confusion is to do both methods:
Direct combinatorial counting:
Count favorable pairs with different color and number.
Divide favorable by total.
Conditional approach:
First card is any card (probability 1).
Probability(second card different color) = 40/49.
Probability(different number given different color) = 36/40.
Multiply.
Comparing these helps confirm consistency and avoids double counting.