High-Card Pot Game
Problem statement
Deal the given deck to players players in round-robin order, starting with player 0. Each player's cards remain in deal order.
During a round, every player who still has a card reveals their next card and all revealed cards enter a shared pot. If exactly one player revealed the highest rank, that player wins every card currently in the pot and the pot becomes empty. If the highest rank is tied, the pot carries into the next round. A pot that remains after all hands are exhausted is unclaimed.
Return the number of cards won by each player.
Function
highCardPotScores(deck: int[], players: int) → int[]Examples
Example 1
deck = [5,3,2,7]players = 2return = [2,2]Player 0 wins the first two cards; player 1 wins the second round.
Example 2
deck = [8,8,2,9,1,3]players = 3return = [6,0,0]The first-round high rank is tied, so all six cards are in the pot when player 0 uniquely reveals 9.
Example 3
deck = [4,4]players = 2return = [0,0]The only round ties, so the final pot is unresolved and unclaimed.
Constraints
2 <= players <= 52.0 <= deck.length <= 100000.- Each card rank is in
[1, 13]; higher numbers beat lower numbers.