Code a poker game: model cards, rank five-card hands and pick the winners
Company: OpenAI
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Technical Screen
Code a poker game. The report names this coding exercise only as "poker game", so settle the scope with the interviewer before writing code. In its usual form, the core is to model a deck of cards and the players' hands, evaluate each hand under the standard poker hand rankings, and decide which player wins, including when hands tie.
For reference, the standard categories from lowest to highest are: high card, one pair, two pair, three of a kind, straight, flush, full house, four of a kind, straight flush. Within a category, hands are compared by the ranks that form the category and then by the remaining cards (the kickers); suits have no rank order.
```hint One comparable value per hand
Think about what evaluating a hand should produce so that deciding between any two hands is a single comparison, with no special case for each pair of categories.
```
```hint Where evaluators break
Before coding, list the hands where the obvious rule gives the wrong answer: the lowest possible straight, two hands that share their higher pair, and two hands that are exactly equal.
```
### Constraints and Clarifications
- Not given: the variant, the number of players, the card format, and whether betting is part of the exercise. Ask, or state your assumptions.
- Use one standard 52-card deck without jokers unless the interviewer says otherwise.
### Clarifying Questions
- Does each player hold exactly five cards, or is it a variant such as two private cards plus five shared cards, where each player uses the best five of seven?
- What is the input format of a card (for example `"AS"`, `"TD"` or `"10D"`), and should malformed or duplicated cards be rejected?
- Can an ace play low in a straight (ace, 2, 3, 4, 5)? Can a straight wrap around (queen, king, ace, 2, 3)?
- When the best hands are exactly equal, is the pot split, or do suits break the tie?
- Is the exercise only dealing and the showdown, or also betting rounds, folding and chips?
- How many players can sit at the table?
### What a Strong Answer Covers
- Settles the variant, card format, ace rules and tie policy before writing code
- A small domain model (card, rank, suit, hand, deck) that rejects duplicates and malformed input
- An evaluator that recognizes every category, including the lowest straight, and produces a value that orders any two hands correctly, kickers included
- Winner selection that returns every tied player
- Deterministic tests (an injectable shuffle) organized by category and tie-break, and a structure that extends to seven-card play or betting
### Follow-up Questions
- Each player now has two private cards plus five shared cards and uses the best five. How do you evaluate the hand, and what does it cost?
- Add betting with folds and all-in players. How do you split the money when an all-in player with less at stake has the best hand?
- How would you test the evaluator exhaustively rather than with a handful of hand-picked hands?
- A simulation needs to evaluate many millions of hands per second. What would you change?
Overview: A coding exercise to build a poker game: model cards, players' hands and a deck, rank five-card hands under the standard poker categories, and decide the winners with correct kicker comparisons and split pots. It tests domain modeling, edge cases such as the ace-low straight, and testable, extensible code.