Compare Complete and Partial Poker Hands
Company: Rippling
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates algorithmic problem-solving, combinatorial reasoning about incomplete information, and the ability to encode domain-specific ranking and tie-breaking rules for poker hands.
Part 1: Compare Complete 5-Card Poker Hands
Constraints
- hand1 and hand2 each contain exactly 5 cards.
- Each card string is valid and uses ranks 2-9, T, J, Q, K, A and suits C, D, H, S.
- No exact card appears more than once across the 10 input cards.
- A-2-3-4-5 counts as a straight with 5 as the high card.
- Suits are only used to detect flushes and straight flushes; suits do not break ties.
Examples
Input: (['9H', 'TH', 'JH', 'QH', 'KH'], ['8C', '8D', '8S', '8H', '2D'])
Expected Output: 'HAND1'
Explanation: A straight flush beats four of a kind.
Input: (['AH', 'AD', 'AC', 'KS', 'KD'], ['QH', 'QC', 'QS', 'JC', 'JD'])
Expected Output: 'HAND1'
Explanation: Both are full houses, but three aces beats three queens.
Input: (['AH', 'AD', 'KC', '7S', '2D'], ['AS', 'AC', 'KD', '7H', '2C'])
Expected Output: 'TIE'
Explanation: Both hands are one pair of aces with the same kickers.
Input: (['AH', '2D', '3S', '4C', '5H'], ['2H', '3D', '4S', '5C', '6H'])
Expected Output: 'HAND2'
Explanation: Edge case: A-2-3-4-5 is a 5-high straight, which loses to a 6-high straight.
Hints
- Convert each hand into a sortable score: first the hand category, then the tie-break values in descending priority.
- Use rank frequencies to detect pairs, trips, quads, and full houses, and handle the special wheel straight A-2-3-4-5 separately.
Part 2: Determine Guaranteed Outcome for Partial Poker Hands
Constraints
- 0 <= len(hand1), len(hand2) <= 5.
- All known cards are valid and no exact card appears more than once across both hands.
- (5 - len(hand1)) + (5 - len(hand2)) <= 3.
- Unknown cards must be filled with distinct cards from the remaining 52-card deck.
- A-2-3-4-5 counts as a straight with 5 as the high card.
- Suits do not break ties.
Examples
Input: (['AH', 'KH', 'QH', 'JH', 'TH'], ['9C', '9D', '9S', '2C'])
Expected Output: 'HAND1'
Explanation: Hand 1 is already a straight flush. Hand 2 has one unknown card but can never beat it.
Input: (['2H', '5D', '7C', '9S'], ['AH', 'AD', 'AC', 'AS', 'KD'])
Expected Output: 'HAND2'
Explanation: Hand 2 already has four aces. Hand 1 has only one unknown card and cannot reach anything stronger.
Input: (['AH', 'AD', 'KC', '7S', '2D'], ['AS', 'AC', 'KD', '7H', '2C'])
Expected Output: 'TIE'
Explanation: Edge case: with no unknown cards, this reduces to comparing two complete hands, and they tie exactly.
Input: (['AH', 'KH', 'QH', 'JH'], ['9C', '9D', '9S', '2C'])
Expected Output: 'UNKNOWN'
Explanation: If hand 1 gets 'TH', it can win with a straight flush. If hand 2 gets '9H' while hand 1 gets something else, hand 2 can win with four of a kind.
Hints
- Build the remaining deck after removing the known cards, then generate every way to distribute the missing cards between the two hands.
- Compare the completed hands exactly as in Part 1, and stop early if you ever see two different outcomes.