Best Poker Category with a Joker
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:
FIVE_OF_A_KINDSTRAIGHT_FLUSHFOUR_OF_A_KINDFULL_HOUSEFLUSHSTRAIGHTNONE
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[]) → StringExamples
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.