Problem · Simulation

Resolve Battles

Learn this problem
HardAirbnb logoAirbnbINTERNOA

Problem statement

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].

More Airbnb problems

drafts saved locally
public List<String> resolveBattles(List<String> actions) {
  // write your code here
}
actions["A Munich Hold", "B Warsaw Support A", "C Bohemia Move Munich"]
expected["A Munich", "B Warsaw", "C [dead]"]
checking account