Problem · Simulation
Fantasy Card Duel
Learn this problemProblem statement
Two players each have a deck of cards. Every card has a power value from 1 through 10. In every round, each player removes the top card of their deck.
- If the first player's card is greater than or equal to the second player's card, the first player places both cards at the bottom of
playerDeckA, with the first player's card followed by the second player's card. - Otherwise, the second player places both cards at the bottom of
playerDeckB, with the second player's card followed by the first player's card.
The game ends when either deck is empty. Return the number of rounds played.
All judged inputs are guaranteed to reach an empty deck and terminate.
Function
fantasyCard(playerDeckA: int[], playerDeckB: int[]) → intExamples
Example 1
playerDeckA = [5]playerDeckB = [2]return = 1
Example 2
playerDeckA = [1, 2]playerDeckB = [3, 1]return = 6Unfortunately, we dont have access to the video explanation they provided..