Find the Best and Worst Completion of a Partial Numeric Hand
Company: Rippling
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
## Problem
Complete a partial numeric card hand to five cards, returning the strongest and weakest possible completed hands under the game rules below. Cards are digits `1` through `9`, repetitions are allowed, and every appended position may use any digit independently.
## Function Contract
Implement `complete_hands(partial_hand)` and return `[best_hand, worst_hand]`. Each result is a five-character string that begins with `partial_hand`.
## Rules
- Categories from strongest to weakest are: five of a kind, four of a kind, full house, two pair, three of a kind, one pair, high card.
- Classify a hand by multiplicities only; there are no suits, straights, or flushes.
- Within the same category, compare the original five card positions from right to left; at the first difference, the larger digit is stronger.
- If `partial_hand` already has length 5, return that hand as both the best and worst completion.
- Use an extensible object-oriented category-evaluator abstraction so adding a category does not require rewriting `complete_hands` or the shared comparison flow.
## Constraints
- `0 <= len(partial_hand) <= 5`.
- Every character in `partial_hand` is a digit from `1` through `9`.
- There are at most `9^5` possible full hands, but avoid duplicating category and tie-break logic between the best and worst searches.
## Examples
```text
partial_hand = "99"
output = ["99999", "99321"]
```
`"99999"` is five of a kind. Because the fixed prefix already contains a pair, one pair is the weakest attainable category; `"99321"` is the weakest such completion under the right-to-left tie-break.
Overview: Find the strongest and weakest five-card completions of a partial numeric hand under custom category and right-to-left tie-break rules while sharing one extensible comparison engine.
Read the full Rippling Software Engineer interview experience this question came from
Complete a partial hand of zero to five digits to exactly five cards. Every missing position may independently be any digit from 1 through 9, and each returned hand must begin with the given prefix. Return a two-element list containing the strongest possible completion followed by the weakest. Categories from strongest to weakest are five of a kind, four of a kind, full house, two pair, three of a kind, one pair, and high card; classification uses multiplicities only. Within one category, compare original positions from right to left, with the first larger digit being stronger. If the input already has five cards, return it twice. Use an extensible object-oriented category-evaluator abstraction and share the same category and tie-break logic between both extrema.
Constraints
- 0 <= len(partial_hand) <= 5.
- Every character in partial_hand is a digit from 1 through 9.
- Each appended position may independently use any digit from 1 through 9.
- There are at most 9^5 possible complete hands.
- Category evaluation uses an extensible object-oriented abstraction shared by the best and worst searches.
Examples
Input: ('99',)
Expected Output: ['99999', '99321']
Explanation: This is the source example: the fixed pair can become five of a kind, while one pair is the weakest attainable category.
Input: ('',)
Expected Output: ['99999', '54321']
Explanation: With no fixed cards, five nines is strongest and the right-to-left-minimal all-distinct hand is weakest.
Hints
- Give every complete hand one comparison key that captures both its category and the right-to-left tie-break.
- During one enumeration of all suffixes, maintain both the maximum and minimum key.