War Card Game Winner
Problem statement
Two players hold card queues from top to bottom. In each battle, both draw their top card. The higher card wins the entire battle pile and appends it to the bottom of that player's queue in draw order, with player one's card before player two's card at each draw.
On a tie, each player draws three more cards; the third new card decides the battle. Ties repeat the same rule. A player who cannot supply all three tie cards loses immediately. Return 1 or 2 for the winner.
Function
warWinner(playerOne: int[], playerTwo: int[]) → intExamples
Example 1
playerOne = [5,1]playerTwo = [3,2]return = 1Player one eventually collects every card.
Constraints
1 <= playerOne.length, playerTwo.length <= 100.- Card values are from 1 through 13.
- Tests do not exhaust both players simultaneously during a tie and terminate within 100000 comparisons.