Problem · Simulation

Fantasy Card Duel

Learn this problem
MediumZipRecruiter logoZipRecruiterINTERNOA

Problem 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[]) → int

Examples

Example 1

playerDeckA = [5]playerDeckB = [2]return = 1
Example 1 illustration

Example 2

playerDeckA = [1, 2]playerDeckB = [3, 1]return = 6
Unfortunately, we dont have access to the video explanation they provided..

Constraints

  • 1 <= playerDeckA.length <= 100
  • 1 <= playerDeckA[i] <= 10
  • More ZipRecruiter problems

    drafts saved locally
    public int fantasyCard(int[] playerDeckA, int[] playerDeckB) {
      // write your code here
    }
    
    playerDeckA[5]
    playerDeckB[2]
    expected1
    checking account