Count Card Duel Rounds
Updated
Problem statement
Given the decks playerDeckA and playerDeckB of two strategists in a fantasy card duel, return how many rounds the duel lasts.
The first player holds playerDeckA and the second player holds playerDeckB. Each card shows a mystical creature with a power value. Index 0 of each array is the top of that deck, and the last index is the bottom.
Each round follows these rules:
- Each player reveals the top card of their deck.
- If the power of the card from
playerDeckAis greater than or equal to the power of the card fromplayerDeckB, the first player wins the round. Both cards go to the bottom ofplayerDeckA: the first player's own card, then the card fromplayerDeckBbelow it. - If the power of the card from
playerDeckAis less than the power of the card fromplayerDeckB, the second player wins the round. Both cards go to the bottom ofplayerDeckB: the second player's own card, then the card fromplayerDeckAbelow it.
The duel ends when a player's deck is empty, because that player cannot draw another card.
Note: You don't need the most optimal solution. Any solution with time complexity no worse than O(playerDeckA.length^3) fits within the time limit.
Function
countDuelRounds(playerDeckA: int[], playerDeckB: int[]) → intExamples
Example 1
playerDeckA = [5]playerDeckB = [2]return = 1Breakdown of each round:
- Round 1:
playerDeckAplays a5, whereasplayerDeckBpresents a2. The decks temporarily become empty.- Since
5 ≥ 2,5and2move to the bottom ofplayerDeckA.- Afterwards,
playerDeckA = [5, 2]andplayerDeckB = [].
- Afterwards,
- With
playerDeckBempty, the duel is over, resulting in a single round:1.
Example 2
playerDeckA = [1,2]playerDeckB = [3,1]return = 6Round 4 is a tie, so the first player wins it. After round 6, playerDeckA is empty, so the duel lasts 6 rounds.
| Round | playerDeckA card | playerDeckB card | Winner | playerDeckA after | playerDeckB after |
|---|---|---|---|---|---|
1 | 1 | 3 | Second player | [2] | [1, 3, 1] |
2 | 2 | 1 | First player | [2, 1] | [3, 1] |
3 | 2 | 3 | Second player | [1] | [1, 3, 2] |
4 | 1 | 1 | First player | [1, 1] | [3, 2] |
5 | 1 | 3 | Second player | [1] | [2, 3, 1] |
6 | 1 | 2 | Second player | [] | [3, 1, 2, 1] |
Constraints
1 <= playerDeckA.length, playerDeckB.length <= 501 <= playerDeckA[i], playerDeckB[i] <= 10- The duel is guaranteed to end.
More Airbnb Online Assessment questions
- Count Lamps Lighting Each PointOA · Seen Nov 2026
- Simulate Orchard Rot SpreadOA · Seen Nov 2026
- Sort Adjacent PairsOA · Seen Nov 2026
- In-Memory File SystemOA · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
- Recipe Management SystemOA · Seen Nov 2026
- Progressive Banking SystemOA · Seen Nov 2026
- Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
- Parcel Attribute Store with TTLOA · Seen Oct 2026
- Parcel Event TrackingOA · Seen Oct 2026
Similar questions at other companies
- Chess TournamentJP Morgan Chase · OAJP Morgan Chase interview questions
- Incident MonitorStripe · OAStripe interview questions
- Realized PnL with Oldest Inventory FirstBelvedere Trading · OA
- Buffet Day GainsUpstart · OAUpstart interview questions
- Bank Requests with Delayed CashbackRamp · OARamp interview questions
- Busy IntersectionIMC Trading · OAIMC Trading interview questions
- Capital Gains Tax from TradesArcesium · OAArcesium interview questions
- Ring Buffer OperationsAmazon · ONSITE INTERVIEW
- Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Implement a Queue Using an ArrayLondon Stock Exchange · PHONE SCREENLondon Stock Exchange interview questions
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)