Reported March 2024
SpaceXsimulation

Monster Registry

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

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

SpaceX reportedly put a Monster Registry task in front of candidates in March 2024, and it's not a classic algorithm puzzle. It's a parsing and formatting problem. You read a CSV of monsters, look one up by case-insensitive name, and print strengths, weaknesses, and an evolution chart. Brute force isn't the risk here, since the input is a small database. The risk is a single wrong space or missing colon failing the automated tests. If you blank on the CSV handling or the DFS output, StealthCoder is the safety net that runs invisibly during the live OA. Know the shape of the task before you open it.

The problem

Task 1
Your task is to create a Monster Registry
Monster Background
Monsters battle each other.
Each monster has a unique 3-digit ID number and a name.
Monsters have types and weaknesses.Types determine what other monsters they are strong or weak against.
For example, a Banub is a fire type monster, and Octopeat has a weakness for fire type monsters. Therefore Banub is strong against Octopeat and Octopeat is weak against Banub.
A single monster can have more than one type or weakness.
A monster can evolve into another monster.For example, Banub evolves into Banubeleon, who evolves into Banubizard.
Sometimes, a monster may have a choice of two or more other monsters to evolve into. For example, Ironuin can evolve into Iroume or Irossom.
Detailed Requirements
The program which you will write shall accept a CSV file containing a database of all known monsters, as well as the case-insensitive name of one monster. It will output the other monsters that the given monster is strong and weak against, and an evolution chart for the given monster.
Your program will be provided well-formed input files and valid command line arguments and must print a carefully formatted output.
Submission Guidelines
The tests will execute the main function without any arguments, parameters will be provided like in command-line execution
All results must be printed to stdout (not returned from the function)
Your submission will be run against an automated test suite. This means proper output formatting is essential for correctness.
To implement your solution, use Python 3.8. You are encouraged to use Python Standard Library modules, but you may not use other 3rd party code.
Database Input File
The first positional argument to your program will be the filename of a comma separated value database file.
The first row of the file contains categorized column headers.Column headers may be sorted in any order.
Each additional row contains the information entries for a specific monster.
Required columns:"ID"
"Name"
"Types"
"Weaknesses"
"Evolution"Contains the ID(s) of next monster evolution(s)
If no further evolution exists, this column will be empty.
Multiple types, weaknesses, or evolution paths will be separated by a single comma and enclosed in double quotes ("").
Monster Registry Output
The second positional argument to your program will be the case-insensitive name of one monster. The program will output the given monster's properties in the following order:
"ID"
"Strong against"
"Weak against"
"Evolution"
Strengths and Weaknesses
Under the category "Strong against", you must output a list of monsters against which your given monster's type is strong.
Each of these monsters shall be printed on a new line in order of monster ID.
If no known monster exist with weaknesses for the given monster's type, print "None".
Under the category "Weak against", you must output a list of monsters against which your given monster's type is weak.
Each of these monsters shall be printed on a new line in order of monster ID.
If no known monster exist which are a type that the given monster is weak against, print "None".
Evolution Chart
The final output category, "Evolution", shall contain an evolution chart for the monster.
Start with the current monsterIf no further evolution is possible, end.
Continue until the final formEach form shall be separated by a single space, a single >, and another single space " > ".
Multiple evolution paths shall be printed on new lines.Evolution paths shall be printed in depth-first-search order, sorted by monster ID.
Output Formatting
Your program must meet the following requirements for output format.
Each category of information shall be followed by a single colon.
The information shall be printed on the following line, indented by 4 spaces.
Print exactly one new line at the end of the output.
Examples Inputs and Outputs
These examples are separated by a blank new line for clarity. This new line must not be included in the expected inputs or outputs.
Example Input File
$ cat database.csv
ID,Name,Types,Weaknesses,Evolution
004,Banub,Fire,"Ground,Rock,Water",005
005,Banubeleon,Fire,"Ground,Rock,Water",006
006,Banubizard,"Fire,Flying","Rock,Electric,Water",
043,Octopeat,"Grass,Poison","Fire,Flying,Ice,Psychic",044
044,Octoplat,"Grass,Poison","Fire,Flying,Ice,Psychic","045,182"
045,Octonyte,"Grass,Poison","Fire,Flying,Ice,Psychic",
182,Bibyss,Grass,"Bug,Fire,Flying,Ice,Poison",
Example Program Output
Example 1
$ python solution database.csv Banubeleon
ID:
005
Strong against:
Octopeat
Octoplat
Octonyte
Bibyss
Weak against:
None
Evolution:
Banubeleon > Banubizard
Example 2
$ python solution database.csv Octopeat
ID:
043
Strong against:
Bibyss
Weak against:
Banub
Banubeleon
Banubizard
Evolution:
Octopeat > Octoplat > Octonyte
Octopeat > Octoplat > Bibyss
Practice Contract
The original task wording above is preserved. In the judged callable form, databaseRows contains the header followed by every CSV data row, monsterName is the case-insensitive query, and the function returns the exact text that the original program prints.
For this exercise, assume monster names are unique when compared case-insensitively, the evolution graph is acyclic, and a monster appears at most once in each strong or weak list even when multiple types match. All lists of monsters are ordered by numeric monster ID. The returned string must include exactly one trailing newline.

Function
buildMonsterRegistry(databaseRows: String[], monsterName: String) → String

Examples
Example 1
databaseRows = ["ID,Name,Types,Weaknesses,Evolution","004,Banub,Fire,\"Ground,Rock,Water\",005","005,Banubeleon,Fire,\"Ground,Rock,Water\",006","006,Banubizard,\"Fire,Flying\",\"Rock,Electric,Water\",","043,Octopeat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",044","044,Octoplat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",\"045,182\"","045,Octonyte,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",","182,Bibyss,Grass,\"Bug,Fire,Flying,Ice,Poison\","]
monsterName = "Banubeleon"
return = "ID:\n 005\nStrong against:\n Octopeat\n Octoplat\n Octonyte\n Bibyss\nWeak against:\n None\nEvolution:\n Banubeleon > Banubizard\n"
Banubeleon is a Fire type, so it is strong against the four monsters whose weaknesses include Fire. No listed monster has a type that matches Banubeleon's weaknesses. Its only evolution path ends at Banubizard.
Example 2
databaseRows = ["ID,Name,Types,Weaknesses,Evolution","004,Banub,Fire,\"Ground,Rock,Water\",005","005,Banubeleon,Fire,\"Ground,Rock,Water\",006","006,Banubizard,\"Fire,Flying\",\"Rock,Electric,Water\",","043,Octopeat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",044","044,Octoplat,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",\"045,182\"","045,Octonyte,\"Grass,Poison\",\"Fire,Flying,Ice,Psychic\",","182,Bibyss,Grass,\"Bug,Fire,Flying,Ice,Poison\","]
monsterName = "Octopeat"
return = "ID:\n 043\nStrong against:\n Bibyss\nWeak against:\n Banub\n Banubeleon\n Banubizard\nEvolution:\n Octopeat > Octoplat > Octonyte\n Octopeat > Octoplat > Bibyss\n"
Octopeat's Grass type is strong against Bibyss, whose weaknesses include Grass. Its Fire weakness makes it weak against the three Fire-type monsters. The evolution graph branches at Octoplat, and DFS visits ID 045 before ID 182.

Constraints
2 ≤ databaseRows.length ≤ 10,001
The first row contains each required header exactly once, in any order.
Every remaining row is well-formed CSV and contains a unique 3-digit ID and a non-empty name.
Names are unique under case-insensitive comparison.
Types, weaknesses, and evolution IDs are comma-separated inside a CSV field and may be empty.
Every evolution ID names a monster in the database, and the evolution graph is acyclic.
The total input size is at most 1,000,000 characters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core is three small pieces. First, parse the CSV with the csv module so quoted multi-value fields like "Fire,Water" split correctly. Build a dict from ID to row and a dict from lowercase name to row. Second, strong against means every monster whose Weaknesses include any of your types. Weak against means every monster whose Types match any of your weaknesses. Use sets, then sort by ID, and print None if empty. Third, the evolution chart is a DFS from the monster. Visit children sorted by ID, carry the path, and print the path joined with " > " when you hit a leaf. The pitfall is formatting: colon after each category, four-space indent, exactly one trailing newline, and stripping whitespace in split values. Also remember the monster itself shouldn't match against itself unless the data says so. StealthCoder is your hedge in the live OA if the output format trips you up.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Monster Registry 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

SpaceX reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Monster Registry FAQ

How hard is the SpaceX Monster Registry problem really?+

The algorithms are easy. It's CSV parsing, set matching, sorting, and a DFS over evolutions. The difficulty is exact output formatting, because the automated tests compare stdout character by character. Treat it as a careful implementation task, not a clever-trick one.

What's the trick to the strong and weak lists?+

Strong against means monsters whose Weaknesses overlap with your monster's Types. Weak against means monsters whose Types overlap with your monster's Weaknesses. Use set intersection checks per row, collect matches, sort by ID, and print None when the list is empty.

How do I print the evolution chart correctly?+

Run a DFS starting at the given monster, visiting children in ascending ID order. Keep the current path as a list of names. At a monster with no evolutions, print the path joined by " > ". Branching monsters produce multiple lines, one per full path.

How do I handle the CSV columns and quoted fields?+

Use csv.DictReader so column order doesn't matter, since headers can be in any order. Quoted fields with commas come back as one string, so split on commas and strip each piece. An empty Evolution field means no further evolution. Match the monster name with lower().

How do I prepare for this in 48 hours?+

Write a small version yourself using sample CSV data. Practice reading argv inside main, printing with exact indentation, and ending with one newline. Test case-insensitive lookup, empty lists, and branching evolutions. That covers nearly every way this task fails.

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

OA at SpaceX?
Invisible during screen share
Get it