Problem · Design
Camel Cards
Learn this problemProblem statement
Camel Cards is a simplified two-player card game. You are given two strings, hand1 and hand2, representing the players' four-card hands. Each card is labeled with a digit from 1 through 9, where 9 is highest.
Hand Types
From strongest to weakest:
- Four of a kind: all four cards are equal, such as
9999. - Two pair: two cards of one value and two cards of another value, such as
2332. - Three of a kind: three equal cards and one different card, such as
9998. - One pair: two equal cards and two other distinct cards, such as
5233. - High card: all four cards are distinct, such as
2345.
Ordering Rules
- A stronger hand type always wins.
- If both hands have the same type, compare their cards from right to left, which is from most recently dealt to first dealt.
- Do not sort the cards. At the first differing position, the hand with the higher card wins.
- If all four cards are equal, the result is a tie.
Return "HAND_1" if hand1 wins, "HAND_2" if hand2 wins, or "TIE".
Design the hand-type evaluation so that more hand types can be added later.
Function
evaluate(hand1: String, hand2: String) → StringExamples
Example 1
hand1 = "2332"hand2 = "2442"return = "HAND_2"Both hands are two pair. Comparing from right to left, the final cards are tied at 2, then hand2 has 4 while hand1 has 3.
Constraints
hand1.length() = hand2.length() = 4- Every character in
hand1andhand2is a digit from1through9.
More Rippling problems
- Delivery Cost TrackerPHONE SCREEN · Seen Jul 2026
- Corporate Card Expense RulesPHONE SCREEN · Seen Jun 2026
- Article Vote TrackerPHONE SCREEN · Seen May 2026
- Employee Resource Access ManagementONSITE INTERVIEW · Seen Jan 2026
- Limit an Organization Tree's HeightONSITE INTERVIEW · Seen Aug 2025
- Distributed System RecoveryOA · Seen Jul 2025
- Server Upgrade PlanningOA · Seen Jul 2025
- Shortest SubstringOA · Seen Jul 2025