Determine the Winner of Three-Card Hands
Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The OpenAI OA reported in September 2026 gives you a poker-lite problem: three-card hands, rank them, return the index of the winner. It looks like a parsing chore, but it hinges on one idea. Turn every hand into a comparable key, a tuple of category followed by ranks sorted in tiebreak order, and let plain tuple comparison do the work. Part 2 adds flush as a category between three of a kind and a pair. Miss that and Example 2 breaks. If you blank on the key design during the live OA, StealthCoder runs invisibly as a safety net.
The problem
Each row of hands is one player's three-card hand. Cards use rank 2 through 9, T, J, Q, K, or A, followed by suit C, D, H, or S. For part = 1, rank categories from strongest to weakest as three of a kind, one pair, and high card. For part = 2, insert flush between three of a kind and one pair. Straights are not a category. Within a category, compare the relevant ranks lexicographically from highest to lowest. A pair compares by pair rank and then kicker. Suits never break a tie. Return the zero-based index of the strongest hand, choosing the smallest index for a complete tie. Function winningHand(hands: String[][], part: int) → int Examples Example 1 hands = [["7C","7D","2S"],["AH","KD","QC"],["5C","5D","5S"]] part = 1 return = 2 Three of a kind outranks both a pair and high card. Example 2 hands = [["2H","9H","KH"],["AS","AD","3C"]] part = 2 return = 0 In part 2, the king-high flush outranks a pair of aces. Example 3 hands = [["QC","QD","AS"],["QH","QS","KC"],["AC","JD","9S"]] part = 2 return = 0 The two pairs share rank queen, so the ace kicker wins. Constraints 2 <= hands.length <= 100000. Every hand contains exactly three distinct valid cards, and no card appears in two hands. part is 1 or 2.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The data structure is a tuple key, one per hand. Map ranks to numbers (2-9, T=10, J=11, Q=12, K=13, A=14). Count rank frequencies. Three of a kind gets category 3 (or 4 in part 2 with flush at 3), a pair gets its category with key [pairRank, kicker], and high card gets the three ranks sorted descending. Flush means all three suits match, and since cards are distinct, a flush can't also be three of a kind or a pair. Part 2 only changes the category numbers. The pitfall is ordering the pair ranks: the pair rank must come before the kicker, so don't just sort all three descending. Scan once, keep the best key, and only replace on strictly greater so the smallest index wins ties. That's O(n) with n up to 100000. Don't sort the whole list.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Determine the Winner of Three-Card Hands cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass OpenAI's OA.
OpenAI reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Determine the Winner of Three-Card Hands FAQ
What's the trick in the OpenAI three-card hands problem?+
Build a comparable key per hand: (category, tiebreak ranks). For a pair, the tiebreak is [pairRank, kicker]. For high card, it's the three ranks descending. Then compare keys with normal tuple comparison and keep the best index. No custom poker logic beyond that.
How does part 2 differ from part 1?+
Part 2 inserts flush between three of a kind and one pair. All three suits match means flush. Flush ties compare by ranks descending like high card. Straights still don't count. Easiest approach is a category lookup that shifts values based on the part parameter.
How do I handle ties so the smallest index wins?+
Loop through hands in order and replace the current best only when the new key is strictly greater. An equal key never replaces it, so the earliest index stays. Suits never break ties, so identical rank patterns are a full tie.
Do I need to sort all the hands?+
No. A single linear pass tracking the best key is enough and runs in O(n). Sorting adds a log factor and complicates the tie rule for index. Only sort the three cards inside each hand.
How should I prepare in 48 hours for this OpenAI OA?+
Practice writing a rank map and a frequency count, then build tuple keys for a few custom hands by hand. Test the three examples, plus a pair versus pair with different kickers and a flush versus pair in part 2. Watch the T, J, Q, K, A mapping, since a string compare breaks them.