Implement Game Metadata Lookups
Problem: Implement Game Metadata Lookups
You are tasked with building an in-memory system to store and query game metadata. The system should be initialized with a list of game records, each containing various attributes. Subsequently, it must support several lookup functions over this data.
Game Metadata Structure
Each game record will include the following fields:
name(string): The title of the game.release_date(string): The game's release date (e.g., "YYYY-MM-DD").platform(list of strings): A list of platforms the game is available on.genre(string): The primary genre of the game.publisher(string): The game's publisher.country(string, optional): The country of origin or primary market.discord_servers(list of strings, optional): Relevant Discord server IDs or names.
Example Input
games = [
{
"name": "Cyber Quest",
"release_date": "2025-01-01",
"platform": ["playstation", "xbox"],
"genre": "RPG",
"publisher": "GameStudio A"
},
{
"name": "Battle Arena",
"release_date": "2024-11-15",
"platform": ["pc"],
"genre": "Action",
"publisher": "GameStudio B"
},
{
"name": "Sky Adventure",
"release_date": "2025-02-10",
"platform": ["playstation"],
"genre": "Adventure",
"publisher": "GameStudio A"
},
{
"name": "Mystery World",
"release_date": "2023-07-20",
"platform": ["xbox", "pc"],
"genre": "Puzzle",
"publisher": "GameStudio C"
},
{
"name": "Speed Racer",
"release_date": "2025-03-05",
"platform": ["pc", "playstation"],
"genre": "Racing",
"publisher": "GameStudio B"
}
]
Required Functions
Implement the following Python functions:
-
def get_genre(input_game: str) -> str | None:- Given a game name, return the genre of that game. Return
Noneif the game is not found.
- Given a game name, return the genre of that game. Return
-
def get_games(input_genre: str) -> list[str]:- Given a genre, return a list of game names associated with that genre.
-
def get_most_available_games() -> list[str]:- Return a list of all game names that are available on the largest number of unique platforms.
-
def get_available_games(number_of_platform: int) -> list[str]:- Return a list of all game names that are available on exactly
number_of_platformunique platforms.
- Return a list of all game names that are available on exactly
Requirements
- Game name and genre lookups must be case-insensitive.
- When counting platforms, only unique platforms for each game should be considered.
- If multiple games tie for the largest number of platforms in
get_most_available_games, all such game names must be returned. - All returned game names must preserve their original casing.
AI interview prep
Core dilemma
Designing an efficient in-memory data structure for diverse lookup patterns (direct, inverted, aggregate) while balancing initialization time, query latency, and memory footprint for potentially large datasets.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Game Metadata Lookups
Problem: Implement Game Metadata Lookups
You are tasked with building an in-memory system to store and query game metadata. The system should be initialized with a list of game records, each containing various attributes. Subsequently, it must support several lookup functions over this data.
Game Metadata Structure
Each game record will include the following fields:
name(string): The title of the game.release_date(string): The game's release date (e.g., "YYYY-MM-DD").platform(list of strings): A list of platforms the game is available on.genre(string): The primary genre of the game.publisher(string): The game's publisher.country(string, optional): The country of origin or primary market.discord_servers(list of strings, optional): Relevant Discord server IDs or names.
Example Input
games = [
{
"name": "Cyber Quest",
"release_date": "2025-01-01",
"platform": ["playstation", "xbox"],
"genre": "RPG",
"publisher": "GameStudio A"
},
{
"name": "Battle Arena",
"release_date": "2024-11-15",
"platform": ["pc"],
"genre": "Action",
"publisher": "GameStudio B"
},
{
"name": "Sky Adventure",
"release_date": "2025-02-10",
"platform": ["playstation"],
"genre": "Adventure",
"publisher": "GameStudio A"
},
{
"name": "Mystery World",
"release_date": "2023-07-20",
"platform": ["xbox", "pc"],
"genre": "Puzzle",
"publisher": "GameStudio C"
},
{
"name": "Speed Racer",
"release_date": "2025-03-05",
"platform": ["pc", "playstation"],
"genre": "Racing",
"publisher": "GameStudio B"
}
]
Required Functions
Implement the following Python functions:
-
def get_genre(input_game: str) -> str | None:- Given a game name, return the genre of that game. Return
Noneif the game is not found.
- Given a game name, return the genre of that game. Return
-
def get_games(input_genre: str) -> list[str]:- Given a genre, return a list of game names associated with that genre.
-
def get_most_available_games() -> list[str]:- Return a list of all game names that are available on the largest number of unique platforms.
-
def get_available_games(number_of_platform: int) -> list[str]:- Return a list of all game names that are available on exactly
number_of_platformunique platforms.
- Return a list of all game names that are available on exactly
Requirements
- Game name and genre lookups must be case-insensitive.
- When counting platforms, only unique platforms for each game should be considered.
- If multiple games tie for the largest number of platforms in
get_most_available_games, all such game names must be returned. - All returned game names must preserve their original casing.