Determine the Winner of Three-Card Hands
Problem statement
Simulate a three-card game for playerCount players numbered from 0 to playerCount - 1. The array dealtCards is the supplied chronological stream of cards to deal. Assign the card at position i to player i % playerCount, starting with player 0. There are exactly three cards per player. Do not shuffle the stream.
The array strategies gives each player's betting rule. It is used only in part 3 and ignored in parts 1 and 2.
Examples
Example 1
dealtCards = ["7C","AH","5C","7D","KD","5D","2S","QC","5S"]playerCount = 3part = 1strategies = ["ALWAYS","ALWAYS","ALWAYS"]return = ["HAND 0 7C 7D 2S","HAND 1 AH KD QC","HAND 2 5C 5D 5S","WINNER 2"]Player 0 receives positions 0, 3, 6: 7C 7D 2S. Player 1 receives AH KD QC, and player 2 receives 5C 5D 5S. In part 1, player 2's three fives beat player 0's pair of sevens and player 1's ace-high hand. The hand rows retain the cards' receipt order, followed by WINNER 2.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 5 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.