FastPrepTurn-Based Monster Battle Simulation
Problems/Turn-Based Monster Battle Simulation

Turn-Based Monster Battle Simulation

OpenAI logoOpenAI● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an OpenAI phone screen for full-time and new grad roles. The battle flow and the chronological log match the source we have. We chose the exact log order and the limits. We left out the source's recommended object boundaries. The counterattack by the final monster is broader than the draw example in the report.

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

You are given two teams of monsters, teamA and teamB. Each team is a list in the order its monsters fight. Each monster is a row [name, health, attack]. health and attack are positive base-10 whole numbers written as strings.

Play out the battle round by round. Return a log of every event, in the order the events happen.

Active monsters

A team's active monster is its first monster whose health is greater than 0. A defeated monster leaves the battle. The team's next living monster becomes active when the next round starts.

Round rules

  1. Team A's active monster attacks Team B's active monster.
  2. If Team B's monster survives, it hits back right away. This counterattack hits Team A's active monster.
  3. There is one exception, the dying counterattack. If both active monsters are the last monsters left on their teams, Team B's monster still makes its counterattack, even when Team A's attack defeats it. This is the only way both teams can be wiped out in the same round.

An attack takes the attacker's attack value away from the defender's health. Health can drop below zero. Do not raise it back up to zero. A monster is defeated when its health becomes 0 or less.

Event log

Return a String[][]. Its rows must be in the exact order the events happen:

  • Each attack adds the row ["ATTACK", attackerTeam, attackerName, defenderTeam, defenderName, damage, healthBefore, healthAfter].
  • Each defeat adds the row ["DEFEATED", team, monsterName], right after the attack that caused it.
  • If the battle goes on and a defeated active monster has a next monster to take its place, add ["ACTIVE", team, replacementName] between the two rounds. If both teams bring in a new monster, log Team A's first.
  • The last row is ["RESULT", result]. result is exactly "Team A wins", "Team B wins", or "Draw".

Write the team names exactly as "Team A" and "Team B". Do not change the input arrays.

Function

simulateMonsterBattle(teamA: String[][], teamB: String[][]) → String[][]

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

Each team has only one monster, so both are the last ones on their teams. Ares defeats Basilisk, so Basilisk makes its dying counterattack. That hit brings Ares down to 0. Both teams are wiped out, so the result is a draw.

Example 2

teamA = [["Ares","8","5"]]teamB = [["Basilisk","6","2"]]return = [["ATTACK","Team A","Ares","Team B","Basilisk","5","6","1"],["ATTACK","Team B","Basilisk","Team A","Ares","2","8","6"],["ATTACK","Team A","Ares","Team B","Basilisk","5","1","-4"],["DEFEATED","Team B","Basilisk"],["ATTACK","Team B","Basilisk","Team A","Ares","2","6","4"],["RESULT","Team A wins"]]

Basilisk survives the first attack and hits back. In the second round Ares defeats it. Both monsters are the last ones on their teams, so Basilisk makes one dying counterattack. Ares survives with health 4, so Team A wins.

Example 3

teamA = [["Ares","4","2"],["Athena","6","3"]]teamB = [["Basilisk","8","5"],["Cyclops","4","1"]]return = [["ATTACK","Team A","Ares","Team B","Basilisk","2","8","6"],["ATTACK","Team B","Basilisk","Team A","Ares","5","4","-1"],["DEFEATED","Team A","Ares"],["ACTIVE","Team A","Athena"],["ATTACK","Team A","Athena","Team B","Basilisk","3","6","3"],["ATTACK","Team B","Basilisk","Team A","Athena","5","6","1"],["ATTACK","Team A","Athena","Team B","Basilisk","3","3","0"],["DEFEATED","Team B","Basilisk"],["ACTIVE","Team B","Cyclops"],["ATTACK","Team A","Athena","Team B","Cyclops","3","4","1"],["ATTACK","Team B","Cyclops","Team A","Athena","1","1","0"],["DEFEATED","Team A","Athena"],["RESULT","Team B wins"]]

Basilisk defeats Ares in the first round, so Athena becomes active. Later Athena defeats Basilisk. Basilisk is not Team B's last monster, so it does not hit back, and Cyclops takes its place. Cyclops survives Athena's attack and then defeats Athena, Team A's last monster. Team B wins.

Constraints

  • 1 <= teamA.length, teamB.length <= 1000.
  • Each monster row has exactly three strings: [name, health, attack].
  • Each name is not empty and has at most 50 Unicode characters.
  • health and attack are positive base-10 whole numbers in the range [1, 10^9], with no plus sign and no leading zeros.
  • The starting health of all monsters on both teams adds up to at most 200000.

More OpenAI Phone Screen questions

  • Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Grid Infection with Recovery After D DaysPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
  • Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
  • Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
  • Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Tax Calculation with Year and Filing RulesGusto · ONSITE INTERVIEWGusto interview questions
  • Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
  • Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Asteroid CollisionSiemens · PHONE SCREEN
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN

OpenAI interview experiences

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[][] simulateMonsterBattle(String[][] teamA, String[][] teamB) {
        // Write your code here.
    }
}
Checking account…