PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/EvenUp

Simulate a two-player card war game

Last updated: Mar 29, 2026

Quick Overview

This question evaluates simulation and queue-based data structure manipulation, deterministic game-state handling, and algorithmic complexity analysis within the Coding & Algorithms domain.

  • Medium
  • EvenUp
  • Coding & Algorithms
  • Software Engineer

Simulate a two-player card war game

Company: EvenUp

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Implement a function to simulate a two-player card game. Each player has a queue of card ranks (top at index 0), with ranks 2–14 where 11–14 represent J, Q, K, A; suits are ignored. In each round, both players draw their top card and compare ranks. The higher rank wins the round; the winner places all cards on the table to the bottom of their deck in the order revealed (winner’s card before opponent’s for each reveal). If the two cards tie, each player must draw exactly three additional cards; if a player cannot provide three additional cards, that player immediately loses. Otherwise, compare the third additional card from each player; the higher rank wins and takes all cards on the table. Continue until one player has no cards. To prevent infinite cycles, either stop if a previously seen (p1_deck, p2_deck) state repeats or after a large round cap (e.g., 1,000, 000), and in that case return a draw. Return the winner (1, 2, or "draw") and the total number of rounds simulated. Aim for O(total cards moved) time and O(n) space, where n is the total number of cards.

Quick Answer: This question evaluates simulation and queue-based data structure manipulation, deterministic game-state handling, and algorithmic complexity analysis within the Coding & Algorithms domain.

EvenUp logo
EvenUp
Aug 10, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
17
0

Implement a function to simulate a two-player card game. Each player has a queue of card ranks (top at index 0), with ranks 2–14 where 11–14 represent J, Q, K, A; suits are ignored. In each round, both players draw their top card and compare ranks. The higher rank wins the round; the winner places all cards on the table to the bottom of their deck in the order revealed (winner’s card before opponent’s for each reveal). If the two cards tie, each player must draw exactly three additional cards; if a player cannot provide three additional cards, that player immediately loses. Otherwise, compare the third additional card from each player; the higher rank wins and takes all cards on the table. Continue until one player has no cards. To prevent infinite cycles, either stop if a previously seen (p1_deck, p2_deck) state repeats or after a large round cap (e.g., 1,000, 000), and in that case return a draw. Return the winner (1, 2, or "draw") and the total number of rounds simulated. Aim for O(total cards moved) time and O(n) space, where n is the total number of cards.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More EvenUp•More Software Engineer•EvenUp Software Engineer•EvenUp Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.