Katkat

Find the Best and Worst Completion of a Partial Numeric Hand

RipplingSoftware Engineer · Technical Screen

Last updated

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.

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

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.