Problem · Array
Find a Game's Genre
Learn this problemProblem statement
Given parallel arrays gameNames and genres, return the genre of inputGame. The value at genres[i] belongs to the game at gameNames[i].
For this exercise, assume game names are unique and comparisons are case-sensitive. If inputGame does not occur in gameNames, return the empty string.
Function
findGameGenre(gameNames: String[], genres: String[], inputGame: String) → StringExamples
Example 1
gameNames = ["Cyber Quest","Battle Arena","Sky Adventure","Mystery World","Speed Racer"]genres = ["RPG","Action","Adventure","Puzzle","Racing"]inputGame = "Mystery World"return = "Puzzle"Mystery World occurs at index 3, so the result is genres[3], which is Puzzle.
Example 2
gameNames = ["Cyber Quest","Battle Arena"]genres = ["RPG","Action"]inputGame = "Unknown Game"return = ""No game name matches Unknown Game, so the function returns the empty string.
Constraints
0 <= gameNames.length <= 10000.genres.length == gameNames.length.- Every value in
gameNamesandgenresis non-empty. - Values in
gameNamesare unique. - Comparisons are case-sensitive.