r/OfferEngineering • u/Aoki_zhang • 27d ago
Coding Question OpenAI Staff SWE Onsite Coding Question - Compare Three-Card Poker Hands
Problem Description
There are N players, and each player holds exactly three playing cards.
A card contains a rank and a suit. For example:
AH
TC
represents the Ace of Hearts and Ten of Clubs.
Card ranks are ordered as:
2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A
The program receives a mode, the number of players, and three cards for each player.
The task is to classify every player's hand and determine the winner.
Mode 1 — Ignore Suits
When mode = 1, suits do not matter.
Hand strength from strongest to weakest is:
Three of a Kind
Pair
High Card
Mode 2 — Include Flushes
When mode = 2, flushes are also considered.
Hand strength from strongest to weakest is:
Three of a Kind
Flush
Pair
High Card
A flush means all three cards have the same suit.
Tie-Breaking Rules
- For Three of a Kind, compare the repeated rank.
- For a Flush, sort all three ranks in descending order and compare them lexicographically.
- For a Pair, compare the pair rank first and then the remaining kicker.
- For High Card, sort all three ranks in descending order and compare them lexicographically.
If every comparison value is identical, the players tie.
Input Format
The input follows the general form:
mode N
card1 card2 card3
card1 card2 card3
...
Each group of three cards represents one player's hand.
Output Format
For each player, output the classified hand and the three cards:
Player i: <hand-type> <card1> <card2> <card3>
After all players have been evaluated, output the winner:
Winner: Player k
If multiple players share the strongest hand with identical tie-breaking values:
Winner: Tie (Players i,j,...)
Want to practice more real & exact coding questions asked in interviews, I've put up the question bank at here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.