Poker Deal and Hand-Winner Simulation
Problem statement
Simulate one five-card poker deal. You are given the players in fixed turn order as userIds and all cards in chronological deal order as dealtCards. Card dealtCards[i] is dealt to player userIds[i % userIds.length].
Each card is a two-character code. Its first character is one of 2 through 9, T, J, Q, K, or A. Its second character is one of C, D, H, or S.
After every player has five cards, compare the hands using standard five-card poker order, from strongest to weakest:
Examples
Example 1
userIds = ["alice","bob"]dealtCards = ["AS","9C","KS","9D","QS","2H","JS","2C","TS","7S"]return = ["DEAL alice AS","DEAL bob 9C","DEAL alice KS","DEAL bob 9D","DEAL alice QS","DEAL bob 2H","DEAL alice JS","DEAL bob 2C","DEAL alice TS","DEAL bob 7S","WINNERS alice"]Alice has an ace-high straight flush. Bob has two pair, so Alice is the only winner.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.