Reported August 2025
EvenUpsimulation

War Card Game Winner

Reported by candidates from EvenUp's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live EvenUp OA. Under 2s to a working solution.
Founder's read

The edge case that kills most naive solutions on this EvenUp OA is the tie rule. Someone reported it in August 2025, and it looks like a friendly card game until two equal cards show up with only two cards left in a hand. This is a pure simulation problem with two queues, and the details are the whole test. You have to track what goes into the pile, in what order, and when a player loses instantly. If you blank on the tie handling mid-assessment, StealthCoder runs invisibly as a safety net and can hand you a working solution while you keep your head straight.

The problem

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

Examples
Example 1
playerOne = [5,1]
playerTwo = [3,2]
return = 1
Player 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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to stop thinking about the game and just build the pile faithfully. Use two deques. Each round, pop one card from each, push both into a pile list as p1 then p2. If one is higher, append the pile to the winner's queue in draw order. On a tie, check that both players have at least three cards. If either doesn't, that player loses right away. Otherwise pop three more from each, add them to the pile, and compare the third cards. Repeat on another tie. The common pitfall is ordering. Pile order has to follow draw order, with player one's card before player two's at each draw, and the pile has to include every tie card. Another miss is checking the three-card requirement after popping instead of before. Cap the loop using the stated comparison limit. If the ordering gets muddy under pressure, StealthCoder is the hedge for the live OA.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill War Card Game Winner cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass EvenUp's OA.

EvenUp reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

War Card Game Winner FAQ

How hard is War Card Game Winner really?+

Easy on algorithms, annoying on details. There's no clever data structure. The difficulty is getting tie handling and pile ordering exactly right. Most failures come from one misplaced append or a missing length check, not from the overall approach.

What's the trick to the tie rule?+

Check both players have at least three cards before drawing anything. If someone is short, they lose immediately. Otherwise draw three more each, add them all to the pile, and compare only the third cards. If those tie too, repeat the same step.

What order do cards go back into the winner's queue?+

Draw order. At each draw, player one's card goes in before player two's. So the pile is p1, p2, then on ties p1, p2 for each of the three extra draws. The winner appends that whole pile to the bottom of their queue.

Which data structure should I use?+

A deque for each player gives O(1) pops from the front and appends to the back. A plain list with pop(0) also works at these sizes since each hand is at most 100 cards, but a deque is cleaner and avoids shifting costs.

How do I prepare for this in 48 hours?+

Write the simulation once from scratch and test it on a tie with short hands, a double tie, and a one-card start. Then run the given example by hand. Simulation problems reward careful tracing more than pattern memorization.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with EvenUp.

OA at EvenUp?
Invisible during screen share
Get it