Design a Card Deck with Shuffling, Dealing, and Five-Card Poker Comparison

Read the full interview experience this question came from →

Quick Overview

Design an object-oriented card deck with unbiased shuffling, atomic dealing, and complete five-card poker rankings, kickers, ace-low straights, and ties.

Design a Card Deck with Shuffling, Dealing, and Five-Card Poker Comparison

Company: Bloomberg

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

Design an object-oriented playing-card system that can shuffle a deck, deal cards, and compare the strength of two five-card poker hands. Explain the responsibilities of the objects and how their behavior preserves a valid deck and consistent hand rankings. ### Constraints & Assumptions - The reported task names shuffling, dealing, and comparing five-card hands but does not specify a poker variant. - **Practice rules:** use a standard 52-card deck with four suits, thirteen ranks, and no jokers. Deal without replacement. Compare standard five-card high-poker hands; suits never break ties. - An ace may be high, or low in the straight A-2-3-4-5. It cannot wrap a straight such as Q-K-A-2-3. - A hand contains exactly five distinct cards. Compare hands from the same deck only after checking that no card appears in both. Equal poker strengths produce a tie. - Choose and document how an attempt to deal more cards than remain is reported. It must not partially consume the deck before failing. - Explain randomness and state management without assuming a particular programming language or random-number library. ### Clarifying Questions to Ask - Which poker variant and ace rules apply? Use the practice rules above for this exercise. - May the remaining undealt cards be reshuffled, and does a reset restore all 52 cards? Define these operations separately. - Should dealing to several players be one atomic request when the deck might run out? ### Part 1 — Model the Deck and Deal Cards Describe the objects, their public operations, and the ownership of mutable state. Show how you would represent a card, track undealt cards, validate hand construction, and reject an oversized deal without losing cards. #### What This Part Should Cover - Immutable card identity based on rank and suit, with deck state held separately. - A single authority for whether a card remains available to deal. - Explicit deal, reset, and exhaustion behavior that preserves uniqueness. ### Part 2 — Shuffle Without Bias Describe how a shuffle changes the order of the currently undealt cards. Explain why all permutations are equally likely when the underlying random draws are uniform, and how you would make the behavior reproducible during testing. #### What This Part Should Cover - The relationship between the random choice made at each step and the set of possible deck permutations. - Separation of a supplied random source from card identity and hand scoring. - Why a random comparison function in a sorting routine does not establish a uniform shuffle. ### Part 3 — Compare Five-Card Hands Define an ordering for all hand categories and specify the tie-breaking information for each category. Explain how a hand evaluator can produce a value that a comparator can order without duplicating poker rules. #### What This Part Should Cover - Straight flush through high card, including ace-low straights and equal-strength ties. - Rank multiplicities, flush detection, straight detection, and category-specific kicker order. - Invalid hand rejection before comparison and a consistent total ordering on valid hand strengths. ```hint Keep state separate from identity A card's rank and suit do not change when it moves from the undealt deck into a hand. Decide which object records that movement. ``` ```hint Compare equal categories Two hands can both contain a pair and still have different strengths. Consider what information remains after their pair ranks are equal. ``` ### What a Strong Answer Covers - Clear boundaries between deck mutation, randomization, immutable hands, and poker-rule evaluation. - An unbiased shuffle argument and deal invariants that prevent duplicate allocation. - A complete category and tie-breaking scheme, including the five-high straight exception. - Time and space costs for shuffling and dealing a generalized deck, and for evaluating a fixed five-card hand. ### Follow-up Questions - How would a batch deal to several players preserve deck state if the total request exceeds the remaining cards? - Which component would change to support a different poker variant without changing the deck's shuffle and deal operations? - Which properties could reveal duplicate cards or inconsistent hand comparisons even when a shuffled deck looks random?

Overview: Design an object-oriented card deck with unbiased shuffling, atomic dealing, and complete five-card poker rankings, kickers, ace-low straights, and ties.

Read the full Bloomberg Software Engineer interview experience this question came from

|Home/Software Engineering Fundamentals/Bloomberg
Bloomberg logo
Bloomberg
Aug 1, 2026
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
1
0

Design an object-oriented playing-card system that can shuffle a deck, deal cards, and compare the strength of two five-card poker hands. Explain the responsibilities of the objects and how their behavior preserves a valid deck and consistent hand rankings.

Constraints & Assumptions

  • The reported task names shuffling, dealing, and comparing five-card hands but does not specify a poker variant.
  • Practice rules: use a standard 52-card deck with four suits, thirteen ranks, and no jokers. Deal without replacement. Compare standard five-card high-poker hands; suits never break ties.
  • An ace may be high, or low in the straight A-2-3-4-5. It cannot wrap a straight such as Q-K-A-2-3.
  • A hand contains exactly five distinct cards. Compare hands from the same deck only after checking that no card appears in both. Equal poker strengths produce a tie.
  • Choose and document how an attempt to deal more cards than remain is reported. It must not partially consume the deck before failing.
  • Explain randomness and state management without assuming a particular programming language or random-number library.

Clarifying Questions to Ask Guidance

  • Which poker variant and ace rules apply? Use the practice rules above for this exercise.
  • May the remaining undealt cards be reshuffled, and does a reset restore all 52 cards? Define these operations separately.
  • Should dealing to several players be one atomic request when the deck might run out?

Part 1 — Model the Deck and Deal Cards

Describe the objects, their public operations, and the ownership of mutable state. Show how you would represent a card, track undealt cards, validate hand construction, and reject an oversized deal without losing cards.

What This Part Should Cover Guidance

  • Immutable card identity based on rank and suit, with deck state held separately.
  • A single authority for whether a card remains available to deal.
  • Explicit deal, reset, and exhaustion behavior that preserves uniqueness.

Part 2 — Shuffle Without Bias

Describe how a shuffle changes the order of the currently undealt cards. Explain why all permutations are equally likely when the underlying random draws are uniform, and how you would make the behavior reproducible during testing.

What This Part Should Cover Guidance

  • The relationship between the random choice made at each step and the set of possible deck permutations.
  • Separation of a supplied random source from card identity and hand scoring.
  • Why a random comparison function in a sorting routine does not establish a uniform shuffle.

Part 3 — Compare Five-Card Hands

Define an ordering for all hand categories and specify the tie-breaking information for each category. Explain how a hand evaluator can produce a value that a comparator can order without duplicating poker rules.

What This Part Should Cover Guidance

  • Straight flush through high card, including ace-low straights and equal-strength ties.
  • Rank multiplicities, flush detection, straight detection, and category-specific kicker order.
  • Invalid hand rejection before comparison and a consistent total ordering on valid hand strengths.

What a Strong Answer Covers Guidance

  • Clear boundaries between deck mutation, randomization, immutable hands, and poker-rule evaluation.
  • An unbiased shuffle argument and deal invariants that prevent duplicate allocation.
  • A complete category and tie-breaking scheme, including the five-high straight exception.
  • Time and space costs for shuffling and dealing a generalized deck, and for evaluating a fixed five-card hand.

Follow-up Questions Guidance

  • How would a batch deal to several players preserve deck state if the total request exceeds the remaining cards?
  • Which component would change to support a different poker variant without changing the deck's shuffle and deal operations?
  • Which properties could reveal duplicate cards or inconsistent hand comparisons even when a shuffled deck looks random?