FastPrepSimulate Multiplayer War
Problems/Simulate Multiplayer War

Simulate Multiplayer War

Palantir logoPalantir● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Palantir intern onsite interview. The report names the card game War, with n players and 3 cards face down during a war.

The report does not say which exact variant to use. This exercise sets a fixed order for the pot, has all players take part, makes a player with too few cards forfeit, and sets a limit on the number of battles. We chose all of these.

Our version is about 70% the same as the reported question.

Simulate a bounded game of War. hands[i] is player i's queue, with the next card at index 0. Higher ranks beat lower ranks. Return the only player still holding cards after at most maxBattles complete battles, or -1 if no unique winner is established.

For this exercise, use these deterministic rules:

  1. At the start of a battle, every player with cards reveals one card. Process players in increasing index order, appending each revealed card to a shared pot.
  2. If exactly one revealed card has the highest rank, its player appends the entire pot to the back of their queue in the order cards entered the pot. The battle ends.
  3. If the highest rank is tied, a war begins. Every player who still has cards participates, including players who revealed a lower rank earlier. In increasing player-index order, a player with at least four remaining cards adds three face-down cards and then one face-up card to the pot, in queue order. A player with fewer than four remaining cards instead adds all remaining cards to the pot and reveals no face-up card.
  4. Compare only the face-up cards of that war stage. A unique highest player wins the pot. A tie repeats step 3 with every player who still has cards. If no face-up card is revealed, return -1.

An entire sequence of tied war stages counts as one battle. If initially exactly one player has cards, return that player even when the limit is zero. Return -1 for an initially empty game or when several players retain cards after the battle limit. Ranks may repeat without restriction; suits and standard-deck composition are not modeled.

Function

warWinner(hands: int[][], maxBattles: int) → int

Examples

Example 1

hands = [[2],[3]]maxBattles = 1return = 1

Both players reveal their only card. Rank 3 wins both cards, leaving only player 1.

Example 2

hands = [[5,2,3,4,9],[5,6,7,8,10]]maxBattles = 1return = 1

The initial fives tie. Each player puts three cards face down, then player 1 reveals 10 against 9 and wins all ten cards.

Example 3

hands = [[8],[8]]maxBattles = 5return = -1

The initial eights tie, but nobody has another face-up card. The war cannot determine a winner.

Constraints

  • 2 <= hands.length <= 6.
  • 0 <= hands[i].length <= 40.
  • 2 <= hands[i][j] <= 14.
  • 0 <= maxBattles <= 10000.

More Palantir interview questions

  • Map and Accumulate Learning QueriesONSITE INTERVIEW · Seen Oct 2026
  • Relational Learning QueriesONSITE INTERVIEW · Seen Apr 2025
  • Find Unmet Users With Shared InterestsONSITE INTERVIEW · Seen Mar 2025
  • Maximum Profit with Repeated Stock TradesONSITE INTERVIEW · Seen Sep 2024
  • Minimum Calls for Repeated API LookupsONSITE INTERVIEW · Seen Oct 2022
  • Find Cookable RecipesONSITE INTERVIEW · Seen Nov 2019
  • Trace Terminal Company OwnershipONSITE INTERVIEW · Seen Nov 2019
  • Query Words Within K PositionsPHONE SCREEN · Seen Nov 2026
  • Basic Item DiscountsOA · Seen Nov 2026
  • Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
  • Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Bounded Token-Bucket Request QueuePlaid · ONSITE INTERVIEWPlaid interview questions
  • Paginate Provider Listings with Per-Page DiversityMaven Clinic · ONSITE INTERVIEWMaven Clinic interview questions
  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Team-Preferred Stable MatchingBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Realized PnL with Oldest Inventory FirstBelvedere Trading · OA
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions

Interview reports that mention this question

  • Palantir FDSE Karat and Learning: 7 Experiences (Part 2 of 2)

Palantir interview experiences

  • Palantir FDSE Experienced-Hire Interviews: 5 Experiences
  • Palantir FDSE New Grad OA Questions: 6 Experiences (Part 2 of 2)
  • Palantir FDSE New Grad Interviews: 5 Experiences (Part 1 of 2)
  • Palantir FDSE Intern OA and Interviews: 3 Experiences
  • Palantir FDSE OA and Interviews: 16 Experiences (Part 1 of 2)
All Palantir interview questionsSee Palantir hiring insights
Saved
class Solution {
    public int warWinner(int[][] hands, int maxBattles) {
        return -1;
    }
}
Checking account…