Problem · Array

Find a Game's Genre

Learn this problem
EasyDiscord logoDiscordFULLTIMEONSITE INTERVIEW

Problem 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) → String

Examples

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 gameNames and genres is non-empty.
  • Values in gameNames are unique.
  • Comparisons are case-sensitive.

More Discord problems

drafts saved locally
public String findGameGenre(String[] gameNames, String[] genres, String inputGame) {
  // write your code here
}
gameNames["Cyber Quest","Battle Arena","Sky Adventure","Mystery World","Speed Racer"]
genres["RPG","Action","Adventure","Puzzle","Racing"]
inputGame"Mystery World"
expected"Puzzle"
checking account