Three-card showdown between two players

0
Sign in

Design a two-player card game that uses a standard 52-card deck.

Each card has a rank and a suit. From lowest to highest, the ranks are 2 3 4 5 6 7 8 9 10 J Q K A. The suits are C D H S. Suits never affect who wins.

Dealing. Draw cards from the top of the deck one at a time. Give them to player 1, then player 2, then player 1, and so on, until each player has three cards. Record every card dealt and the player who received it.

Hand categories, from strongest to weakest:

  1. Three of a kind: all three cards have the same rank.
  2. Pair: exactly two cards have the same rank.
  3. High card: all three ranks are different.

The hand in the stronger category wins. If both hands are in the same category:

  • Three of a kind: the higher rank wins.
  • Pair: compare the ranks of the pairs. If they are equal, compare the third card (the kicker).
  • High card: compare the highest cards, then the second-highest, then the lowest.

If every compared rank is equal, the game is a draw.

Implement

  • A deck that can be built from an exact list of cards (for tests) or shuffled, with an optional seed.
  • deal(): deals the six cards as described and records the deal order.
  • winner() -> int: returns 1 or 2 for the winning player, or 0 for a draw.
  • report() -> str: shows the deal log, both hands with their categories, and the result.

Example 1

Deck order (top first): 9C, QH, 9S, 4D, 2H, 4C

  • Player 1 gets 9C 9S 2H: a pair of 9s.
  • Player 2 gets QH 4D 4C: a pair of 4s.
  • Result: player 1 wins, because the pair of 9s beats the pair of 4s. Player 2's queen does not matter.

Example 2

  • Player 1 holds KS 8D 3C and player 2 holds KH 8C 3S.
  • Both hands are high card with the same ranks, K, 8 and 3, so the result is 0 (draw).

Constraints

  • Each game deals exactly six cards from one deck, and no card is dealt twice.
  • If the deck runs out during the deal, raise an error.

Reconstructed from the reported question; details may differ from what interviewers ask.

OpenAITechnical phone screenEasyLast asked Sep 2026

Sign in to see the worked answer

The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.