Card Game Program: Rank Three-Card Hands and Print the Winner

Read the full interview experience this question came from →

Quick Overview

A coding exercise to model a card game where two or more players each hold three cards, compare the hands under a ranked list of rules, and print the winner along with every player's cards. It tests hand classification, tie-breaking, clean data modeling, and finishing working code within a short round.

Card Game Program: Rank Three-Card Hands and Print the Winner

Company: OpenAI

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: hard

Interview Round: Technical Screen

Write a program for a card game with 2 to n players. Each player holds 3 cards. A list of rules decides which of two hands is stronger: use the rules to compare all the players' hands, then print the winner and every player's cards. Dealing the cards is not the focus here; comparing hands is. The interviewer expected working code within the round, with little time to spare, so keep the design small and the comparison easy to check. The exact rules were not reported. The ranking below, a common one for three-card hands, is an illustrative assumption that makes the task concrete; confirm the real list with the interviewer before coding. ```text hand categories, strongest first (illustrative) 1. straight flush three consecutive ranks, all of the same suit 2. three of a kind three cards of the same rank 3. straight three consecutive ranks 4. flush three cards of the same suit 5. pair two cards of the same rank 6. high card anything else ranks, low to high: 2 3 4 5 6 7 8 9 10 J Q K A suits: S H D C input (illustrative format) P1: 7H 7D KC P2: 4S 5S 6S P3: AC KD 9H ``` ```hint Same category, different strength Two pairs, or two flushes, still need an order. For each category, decide which cards are compared and in what sequence before writing any comparison code. ``` ```hint Keep the rules in one place Suppose the interviewer adds a rule or swaps the order of two. Check how many places in your code would have to change. ``` ### Constraints and Clarifications - At least 2 players, exactly 3 cards each. - Assume the cards come from one standard 52-card deck, so no card appears twice; reject input that breaks this. ### Clarifying Questions - What is the exact list of rules, and in what order? Are straights and flushes in it at all? - Can an ace be low (A-2-3), high (Q-K-A), or both? Can a straight wrap around (K-A-2)? - When two hands are in the same category, which cards break the tie, and in what order? Do suits ever break a tie? - If two or more players tie for the best hand, are there several winners, or is there another rule? - Are the hands given as input, or does the program deal them from a shuffled deck? - What exactly should the output look like? ### What a Strong Answer Covers - Confirms the rule list, ace handling, tie-break order and the outcome of a tie for first place before coding - A small model of cards, hands and categories, with input validation (card format, three distinct cards per player, at least two players) - A comparison that orders by category first and then by the right cards in the right order, including a pair's third card - Correct winner selection among n players, including ties for first place - Output of the winner and every player's cards in a deterministic order - Tests at every category boundary and tie case, and code that is complete within the time limit ### Follow-up Questions - Add a rule that places a new kind of hand between two existing categories. What changes in your code? - Rank all n players from first to last instead of finding only the winner. What changes, and at what cost? - The deck gains jokers that can stand for any card. How do you evaluate a hand that holds one? - How would you test the comparison to be confident it is consistent, so that no three hands beat each other in a circle?

Overview: A coding exercise to model a card game where two or more players each hold three cards, compare the hands under a ranked list of rules, and print the winner along with every player's cards. It tests hand classification, tie-breaking, clean data modeling, and finishing working code within a short round.

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

OpenAI logo
OpenAI
Oct 14, 2026
hardSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
1
0

Write a program for a card game with 2 to n players. Each player holds 3 cards. A list of rules decides which of two hands is stronger: use the rules to compare all the players' hands, then print the winner and every player's cards. Dealing the cards is not the focus here; comparing hands is. The interviewer expected working code within the round, with little time to spare, so keep the design small and the comparison easy to check.

The exact rules were not reported. The ranking below, a common one for three-card hands, is an illustrative assumption that makes the task concrete; confirm the real list with the interviewer before coding.

hand categories, strongest first (illustrative)
  1. straight flush    three consecutive ranks, all of the same suit
  2. three of a kind   three cards of the same rank
  3. straight          three consecutive ranks
  4. flush             three cards of the same suit
  5. pair              two cards of the same rank
  6. high card         anything else

ranks, low to high: 2 3 4 5 6 7 8 9 10 J Q K A
suits: S H D C

input (illustrative format)
  P1: 7H 7D KC
  P2: 4S 5S 6S
  P3: AC KD 9H

Constraints and Clarifications

  • At least 2 players, exactly 3 cards each.
  • Assume the cards come from one standard 52-card deck, so no card appears twice; reject input that breaks this.

Clarifying Questions Guidance

  • What is the exact list of rules, and in what order? Are straights and flushes in it at all?
  • Can an ace be low (A-2-3), high (Q-K-A), or both? Can a straight wrap around (K-A-2)?
  • When two hands are in the same category, which cards break the tie, and in what order? Do suits ever break a tie?
  • If two or more players tie for the best hand, are there several winners, or is there another rule?
  • Are the hands given as input, or does the program deal them from a shuffled deck?
  • What exactly should the output look like?

What a Strong Answer Covers Guidance

  • Confirms the rule list, ace handling, tie-break order and the outcome of a tie for first place before coding
  • A small model of cards, hands and categories, with input validation (card format, three distinct cards per player, at least two players)
  • A comparison that orders by category first and then by the right cards in the right order, including a pair's third card
  • Correct winner selection among n players, including ties for first place
  • Output of the winner and every player's cards in a deterministic order
  • Tests at every category boundary and tie case, and code that is complete within the time limit

Follow-up Questions Guidance

  • Add a rule that places a new kind of hand between two existing categories. What changes in your code?
  • Rank all n players from first to last instead of finding only the winner. What changes, and at what cost?
  • The deck gains jokers that can stand for any card. How do you evaluate a hand that holds one?
  • How would you test the comparison to be confident it is consistent, so that no three hands beat each other in a circle?