Problem · Simulation

Turn-Based Monster Battle Simulation

MediumOpenAI logoOpenAIFULLTIMEPHONE SCREEN

Problem statement

You are given two ordered monster teams, teamA and teamB. Each monster row is [name, health, attack], where health and attack are positive base-10 integers represented as strings.

Simulate their turn-based battle and return a detailed chronological event log.

Active monsters

The active monster of a team is its first monster whose health is greater than 0. A defeated monster leaves the battle, and the next living monster becomes active at the start of the next round.

The problem statement continues
Pro

Examples

Example 1

teamA = [["Ares","4","4"]]teamB = [["Basilisk","4","4"]]return = [["ATTACK","Team A","Ares","Team B","Basilisk","4","4","0"],["DEFEATED","Team B","Basilisk"],["ATTACK","Team B","Basilisk","Team A","Ares","4","4","0"],["DEFEATED","Team A","Ares"],["RESULT","Draw"]]

Both teams begin with their final monster. Ares defeats Basilisk, so the dying-counterattack exception applies. Basilisk also reduces Ares to 0, and the result is a draw.

FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 OpenAI interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week