FastPrepBest Poker Category with a Joker

Best Poker Category with a Joker

Scale AI logoScale AI● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

For this exercise, assume cards contains exactly five poker cards. A non-Joker card is encoded as its rank followed by its suit.

  • Ranks are 2 3 4 5 6 7 8 9 T J Q K A.
  • Suits are C D H S.
  • At most one entry is the literal JOKER.

The Joker may represent any rank and suit; as a wildcard it may supply a fifth card of an existing rank. Return the strongest category that the hand can achieve, using this order:

  1. FIVE_OF_A_KIND
  2. STRAIGHT_FLUSH
  3. FOUR_OF_A_KIND
  4. FULL_HOUSE
  5. FLUSH
  6. STRAIGHT
  7. NONE

A straight contains five consecutive ranks. Ace may be high in T-J-Q-K-A or low in A-2-3-4-5. A straight flush is both a straight and a flush. Only the listed categories are returned.

Function

bestPokerCategory(cards: String[]) → String

Examples

Example 1

cards = ["9C","TC","JC","QC","JOKER"]return = "STRAIGHT_FLUSH"

The Joker can become KC, producing the club straight flush 9-T-J-Q-K.

Example 2

cards = ["AS","AH","AD","AC","JOKER"]return = "FIVE_OF_A_KIND"

The four Aces plus a Joker form five of a kind, the strongest reported category.

Example 3

cards = ["2C","2D","7H","9S","KC"]return = "NONE"

The hand does not satisfy any listed category. Pair is deliberately not one of the possible return values.

Constraints

  • cards.length == 5.
  • Every non-Joker card uses a valid rank and suit.
  • Non-Joker cards are distinct.
  • At most one card is JOKER.
  • Return exactly one of the seven documented category strings.

More Scale AI problems

See Scale AI hiring insights
public String bestPokerCategory(String[] cards) {
    // Write your solution here
}
cards["9C","TC","JC","QC","JOKER"]
expected"STRAIGHT_FLUSH"
Checking account…