PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Rippling
  • Coding & Algorithms
  • Software Engineer

Compare Complete and Partial Poker Hands

Company: Rippling

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a simplified poker-hand comparator. You are given two poker hands. A complete hand contains exactly 5 cards. Each card has a rank and, if needed by your implementation, a suit. The usual poker ranking order should be used, from strongest to weakest: 1. Straight flush 2. Four of a kind 3. Full house 4. Flush 5. Straight 6. Three of a kind 7. Two pair 8. One pair 9. High card For complete hands, return which hand wins, or return `TIE` if both hands have exactly the same strength after all tie breakers are applied. Then extend the function to support partial hands. A partial hand may contain fewer than 5 known cards; the remaining cards are unknown and can be filled with any valid cards. Given two partial hands, determine whether the winner is already guaranteed: - Return `HAND1` if every possible completion of the two hands makes hand 1 win. - Return `HAND2` if every possible completion of the two hands makes hand 2 win. - Return `TIE` if every possible completion results in an exact tie. - Return `UNKNOWN` if different valid completions can lead to different outcomes. For example, if one partial hand is represented as four 9s and the other as a single 9, the winner cannot be determined from the known cards alone, so the result should be `UNKNOWN`.

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

Given two complete 5-card poker hands, return 'HAND1' if the first hand wins, 'HAND2' if the second hand wins, or 'TIE' if they are exactly equal after all standard poker tie-breakers. Use these hand categories from strongest to weakest: straight flush, four of a kind, full house, flush, straight, three of a kind, two pair, one pair, high card. A-2-3-4-5 is the lowest straight, and suits do not break ties.

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

  1. Convert each hand into a sortable score: first the hand category, then the tie-break values in descending priority.
  2. 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

You are given two partial poker hands. Each hand contains 0 to 5 known cards, and the missing cards are unknown. Unknown cards must be filled from the remaining cards of a standard 52-card deck, with no duplicates across either hand. Determine whether the result is already forced: return 'HAND1' if every valid completion makes hand 1 win, 'HAND2' if every valid completion makes hand 2 win, 'TIE' if every valid completion ends in an exact tie, or 'UNKNOWN' if different valid completions can produce different outcomes. Use the same poker ranking and tie-break rules as in Part 1. For this problem, the total number of unknown cards across both hands is at most 3, so exhaustive search is feasible.

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

  1. Build the remaining deck after removing the known cards, then generate every way to distribute the missing cards between the two hands.
  2. Compare the completed hands exactly as in Part 1, and stop early if you ever see two different outcomes.
Last updated: May 30, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Courier Delivery Cost Tracking - Rippling (medium)
  • Implement Article Vote Tracking - Rippling (medium)
  • Implement logger and card ranking - Rippling (medium)
  • Design a Driver Payroll System - Rippling (medium)
  • Compare Complete or Partial Hands - Rippling (medium)