Best Poker Hand - Problem
You are given an integer array ranks and a character array suits. You have 5 cards where the i-th card has a rank of ranks[i] and a suit of suits[i].
The following are the types of poker hands you can make from best to worst:
- "Flush": Five cards of the same suit.
- "Three of a Kind": Three cards of the same rank.
- "Pair": Two cards of the same rank.
- "High Card": Any single card.
Return a string representing the best type of poker hand you can make with the given cards.
Note that the return values are case-sensitive.
Input & Output
Example 1 — Three of a Kind
$
Input:
ranks = [13,2,10,10,10], suits = ["a","a","b","c","a"]
›
Output:
"Three of a Kind"
💡 Note:
Three cards have rank 10, which gives us Three of a Kind (better than checking for flush or pair)
Example 2 — Flush
$
Input:
ranks = [4,4,11,9,7], suits = ["d","d","d","d","d"]
›
Output:
"Flush"
💡 Note:
All five cards have the same suit 'd', so we have a Flush (best possible hand in this problem)
Example 3 — Pair
$
Input:
ranks = [10,10,5,3,1], suits = ["a","b","c","d","e"]
›
Output:
"Pair"
💡 Note:
Two cards have rank 10. No flush (all different suits), no three of a kind, so we have a Pair
Constraints
- ranks.length == suits.length == 5
- 1 ≤ ranks[i] ≤ 13
- suits[i] ∈ {'a', 'b', 'c', 'd'}
Visualization
Tap to expand
Understanding the Visualization
1
Input Cards
5 cards with ranks and suits
2
Count Frequencies
Count suits for flush, ranks for pairs/three of a kind
3
Classify Hand
Return best hand type based on counts
Key Takeaway
🎯 Key Insight: Count frequencies and check hand types in order of precedence: Flush → Three of a Kind → Pair → High Card
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code