Resolve Battles
Updated
Problem statement
This problem models a single turn of a strategy board game. Each string in actions is one army's order for the turn. It gives the army's name, the location where the army starts, and its action.
A Munich Hold: armyAstays in Munich.B Bohemia Move Munich: armyBleaves Bohemia and moves to Munich.C Warsaw Support B: armyCstays in Warsaw and adds 1 to the strength of armyB.
All orders happen at the same time. Resolve the turn with these rules:
- Every army starts with strength 1.
- A moving army ends the turn at its target location. A holding or supporting army ends the turn where it started.
- An army counts as attacked when another army's Move order targets the location where it starts. The support order of an attacked army is canceled.
- Every support order that is not canceled adds 1 to the strength of the army it names, whatever that army's own order is.
- An army that ends the turn alone at its location survives there.
- When several armies end at the same location, the one with the highest strength survives and the others there are defeated. If two or more of them share the highest strength, every army at that location is defeated, including any weaker ones.
Return one string per army, sorted by army name. The string is name location with the location where the army ends the turn, or name [dead] for an army that was defeated.
Sort the names with a plain string comparison, one character at a time by character code. So digits come before uppercase letters, uppercase letters come before lowercase letters, and Army10 comes before Army2. This is the order a default string sort gives in every supported language.
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]"]C moves to Munich, so A and C both end in Munich. Nobody moves to Warsaw, so B is not attacked and its support counts. A has strength 2 and C has strength 1. A is the only strongest army in Munich, so A survives and C is defeated. B stays in Warsaw.
Example 2
actions = ["A Munich Hold", "B Warsaw Move Bohemia"]return = ["A Munich", "B Bohemia"]B goes to Bohemia while A keeps its place in Munich. No other army finishes in either place, so both survive.
Example 3
actions = ["A Munich Hold", "B Bohemia Move Munich", "C Warsaw Support B"]return = ["A [dead]", "B Munich", "C Warsaw"]B moves to Munich, where A holds. Nobody moves to Warsaw, so C's support counts and B has strength 2. A has strength 1. B is the only strongest army in Munich, so B survives there and A is defeated. C stays in Warsaw.
Example 4
actions = ["A Munich Hold", "B Bohemia Move Munich", "C Prussia Move Munich", "D Warsaw Hold"]return = ["A [dead]", "B [dead]", "C [dead]", "D Warsaw"]Three armies finish in Munich: A, B and C, each with strength 1. The highest strength is shared, so all three are defeated. D ends alone in Warsaw and survives.
Example 5
actions = ["A Munich Support B", "B Bohemia Move Prussia", "C Prussia Hold", "D Warsaw Move Munich"]return = ["A [dead]", "B [dead]", "C [dead]", "D [dead]"]D moves to Munich, where A starts. So A is attacked and its support for B is canceled. In Prussia, B and C tie at strength 1, so both are defeated. In Munich, A and D also tie at strength 1, so both are defeated too.
Example 6
actions = ["A Munich Support B", "B Oakland Move Munich"]return = ["A [dead]", "B [dead]"]B moves to Munich, where its own supporter A starts. So A is attacked and its support is canceled. In Munich, A and B tie at strength 1, so both are defeated.
Example 7
actions = ["Army00000000 Hillsborough00000000 Move Burlingame", "Army00000001 Hillsborough00000001 Move Burlingame", "Army00000002 Hillsborough00000002 Move Burlingame", "Army00000003 Hillsborough00000003 Move Burlingame", "Army00000004 Hillsborough00000004 Move Burlingame", "Army00000005 Hillsborough00000005 Move Burlingame", "Army00000006 Hillsborough00000006 Move Burlingame", "Army00000007 Hillsborough00000007 Move Burlingame", "Army00000008 Hillsborough00000008 Move Burlingame", "Army00000009 Hillsborough00000009 Move Burlingame", "Army00000010 Hillsborough00000010 Move Burlingame", "Army00000011 Hillsborough00000011 Move Burlingame", "Army00000012 Hillsborough00000012 Move Burlingame", "B Millbrae Support Army00000010"]return = ["Army00000000 [dead]", "Army00000001 [dead]", "Army00000002 [dead]", "Army00000003 [dead]", "Army00000004 [dead]", "Army00000005 [dead]", "Army00000006 [dead]", "Army00000007 [dead]", "Army00000008 [dead]", "Army00000009 [dead]", "Army00000010 Burlingame", "Army00000011 [dead]", "Army00000012 [dead]", "B Millbrae"]The 13 armies Army00000000 to Army00000012 all move to Burlingame. Nobody moves to Millbrae, so B's support counts. Army00000010 has strength 2 and the other 12 movers have strength 1. It is the only strongest army in Burlingame, so it survives there and the other 12 are defeated. B stays in Millbrae. Every name that starts with A comes before B, so B is listed last.
Example 8
actions = ["Zed Paris Move Rome", "Army2 Lima Hold", "b7 Oslo Support Zed", "Army10 Rome Hold"]return = ["Army10 [dead]", "Army2 Lima", "Zed Rome", "b7 Oslo"]Zed moves to Rome, where Army10 holds. Nobody moves to Oslo, so b7's support counts and Zed has strength 2 against strength 1 for Army10. Zed survives in Rome and Army10 is defeated. Army2 and b7 stay where they started. In the sorted list, Army10 comes before Army2 because the character 1 comes before the character 2. Zed comes before b7 because uppercase letters come before lowercase letters.
Constraints
- Every input follows these rules: every army appears in exactly one order, a Move order never targets the army's own starting location, an army never supports itself, and every supported army appears in
actions. - Each order has the form
name location Hold,name location Move targetorname location Support army, with one space between words. - Practice bound:
1 ≤ actions.length ≤ 1000 - Practice bound: army names and location names are 1 to 20 characters long and use only English letters and digits.
- Practice bound: no two armies start in the same location.
Source note: Original source screenshot 3 of 3 shows support cancellation, tie outcomes, and the array-of-strings I/O format.
More Airbnb interview questions
- In-Memory File SystemOA · Seen Nov 2026
- Shortest Uncommon SubstringONSITE INTERVIEW · Seen Nov 2026
- Task Management SystemOA · Seen Nov 2026
- Recipe Management SystemOA · Seen Nov 2026
- Progressive Banking SystemOA · Seen Nov 2026
- Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Parcel Attribute Store with TTLOA · Seen Oct 2026
Similar questions at other companies
- Evolving Merchant Clusters and Persistent PinsStripe · OAStripe interview questions
- Network Endpoint or Cycle BoundaryOpenAI · OA · PHONE SCREENOpenAI interview questions
- Group Training Overdue RollupVanta · PHONE SCREEN
- Corporation Reporting LinesMicrosoft · PHONE SCREENMicrosoft interview questions
- Detect a Deadlock from Lock LogsHelm.ai · PHONE SCREEN
- Disaster RecoveryHeadlands Technologies · OAHeadlands Technologies interview questions
- Power Cell BankOptiver · OAOptiver interview questions
- LFU CacheSnowflake · OA · ONSITE INTERVIEWSnowflake interview questions
- Arithmetic Triplets After QueriesCapital One · OACapital One interview questions
- Four-Level Banking System with Scheduled PaymentsZipRecruiter · OAZipRecruiter interview questions