Fix the safe level lookup in a mobile game

Review the AI's codeEasy10 min

Your task

An AI wrote Kotlin game code that looked up a level's config with levelConfigs[id]!! and its music with soundtracks[config.themeId]!!. It worked for the campaign levels, then crashed with a NullPointerException on community and seasonal levels that the maps did not know. The fix looks both up safely and falls back instead of crashing.

An assistant wrote resolve_level_track(level_ids, level_themes, soundtrack_themes, requested_id). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • level_ids and level_themes: each known level's id and its theme, at the same index.
  • soundtrack_themes: the themes that ship with a music track.
  • requested_id: the level the player wants to start.
  • Return missing_level, track:default or track:<theme>.

Rules the tests check:

  • Find the first index where level_ids equals requested_id exactly, case included. If there is none, return missing_level.
  • If level_themes has no entry at that index, return missing_level.
  • If that level's theme is in soundtrack_themes, return track: followed by the theme. Otherwise return track:default.
  • An empty theme is a theme like any other.

Examples

resolve_level_track(level_ids: list[str], level_themes: list[str], soundtrack_themes: list[str], requested_id: str) -> str
Example 1
Inputresolve_level_track(["c1", "c2", "s1"], ["forest", "cave", "winter"], ["forest", "cave"], "c2")
Output"track:cave"
Example 2
Inputresolve_level_track(["c1", "c2", "s1"], ["forest", "cave", "winter"], ["forest", "cave"], "s1")
Output"track:default"
Example 3
Inputresolve_level_track(["c1", "c2", "s1"], ["forest", "cave", "winter"], ["forest", "cave"], "ugc-9134")
Output"missing_level"