Reported October 2019
Airbnbsimulation

Resolve Battles

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

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

Airbnb reportedly asked this one in October 2019, and the detail that trips people is the support-cancel rule. Each line is an army order: Hold, Support, or Move. Everything resolves at the same time, so you can't just process the list top to bottom. If you've got an OA coming up, this is a simulation problem dressed up as a war game. Parse carefully, compute strengths, then resolve each destination. If you blank on the ordering of steps during the live assessment, StealthCoder runs invisibly as a safety net while you work.

The problem

The input is a list of strings, each describing one army's action.
A Munich Hold means Army A stays in Munich.
B Warsaw Support A means Army B stays in Warsaw and adds one strength to Army A.
C Bohemia Move Munich means Army C moves toward Munich.
If a supporting army's starting location is attacked by any Move order, its support is canceled.
Practice rule
All orders are resolved at the same time.
A moving army finishes at its target location. A holding or supporting army stays at its starting location.
At each destination, the unique strongest army survives and every weaker army is defeated.
If two or more armies tie for the highest strength, every army at that destination is defeated.
Return one result per army in input order, formatted as Army Location or Army [dead].

Function
resolveBattles(actions: List<String>) → List<String>

Examples
Example 1
actions = ["A Munich Hold", "B Warsaw Support A", "C Bohemia Move Munich"]
return = ["A Munich", "B Warsaw", "C [dead]"]
In this scenario, Army C has a strength of 1, and Army A has a strength of 2 (due to support from Army B). As a result, Army C loses, and Army A successfully defends Munich. The final state of each army is as follows:
Army A remains in Munich.
Army B remains in Warsaw.
Army C is defeated and is marked as [dead].

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is doing it in phases, not in one pass. Phase one: parse each action into army, start location, order type, and target. Phase two: find every location that is the target of a Move, and cancel support for any supporting army sitting at one of those locations. Phase three: compute strength, which is 1 plus the count of active supporters for that army. Phase four: group armies by final location (movers go to the target, others stay) using a hash map, then keep only the unique max strength. A tie at the top kills everyone there. The common pitfall is canceling support after you've already counted strength, or letting a tied group leave a survivor. Also keep output in input order and print the [dead] format exactly. If the phases blur under pressure, StealthCoder can be your hedge during the live OA.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Resolve Battles 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 would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Airbnb reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Resolve Battles FAQ

How hard is the Airbnb Resolve Battles question really?+

Medium at most. There's no fancy algorithm. The difficulty is parsing and getting the order of resolution right. If you split it into parse, cancel support, compute strength, resolve destinations, it's a clean 40-line solution.

What's the trick to Resolve Battles?+

Support cancellation has to happen before strength is counted. Collect all Move targets first, then any supporter standing at one of those locations loses its support. Only then tally strengths and group armies by final location.

How do ties work in this problem?+

If two or more armies share the highest strength at a destination, all armies there die, including the ones with lower strength that would have lost anyway. Only a unique maximum survives. Check the count of armies at the max, not just the max value.

Is this simulation pattern still asked since the October 2019 report?+

Rule-based simulation questions keep showing up in OAs because they test careful reading and clean state handling. The war theme may change, but parse-then-resolve problems with simultaneous updates are still common.

How do I prepare for this in 48 hours?+

Write the solution once from scratch using a hash map from location to list of armies. Test the sample, then add cases for a canceled support, a three-way tie, and a mover whose target holds a stronger army. Watch the output format.

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

OA at Airbnb?
Invisible during screen share
Get it