FastPrepBest and Worst Camel Card Completions

Best and Worst Camel Card Completions

Rippling logoRippling● HardFULLTIMEPHONE SCREEN
Learn

Problem statement

A five-card hand uses ranks 1 through 9, with repeated ranks allowed. Hand categories from strongest to weakest are five of a kind, four of a kind, full house, three of a kind, two pair, one pair, and high card.

Within a category, compare groups by decreasing multiplicity and then decreasing rank. For example, compare the repeated rank before kickers; compare remaining kickers from high to low.

Given the ranks already present in a partial hand, add ranks until it has five cards. Return two canonical strings: the strongest possible completed hand and the weakest possible completed hand. Canonical strings list all five ranks in descending order.

Function

completeCamelCardHands(partial: String) → String[]

Examples

Example 1

partial = "99"return = ["99999","99321"]

Five nines is strongest. A single pair of nines with the three lowest distinct kickers is weakest.

Example 2

partial = "12345"return = ["54321","54321"]

The hand is already complete, so both answers are its canonical ordering.

Example 3

partial = "1112"return = ["21111","32111"]

Adding 1 creates four of a kind. Adding the lowest new kicker 3 leaves three of a kind and is weakest.

Constraints

  • 1 <= partial.length <= 5.
  • Every character in partial is a digit from 1 through 9.
  • Added ranks may repeat without a deck-count limit.

More Rippling problems

See Rippling hiring insights
public String[] completeCamelCardHands(String partial) {
    // Write your solution here.
}
partial"99"
expected["99999", "99321"]
Checking account…