Need help with Graph Traversal Question

Previous Google question:

Question:

You are a game developer working on a game that randomly generates levels. A level is an undirected graph of rooms, each connected by doors. The player starts in one room, and there is a treasure in another room. Some doors are locked, and each lock is opened by a unique key. A room may contain one of those unique keys, or the treasure, or nothing.

Since you are generating levels randomly, you need to ensure the level is solvable. Otherwise, players will get upset. We need you to implement a function that takes your level and validates that it is solvable.

Example:
https://pastebin.com/TLWXeUq0

# You are given a valid starting_point in graph representation

The idea would be to create a Room class which would correspond to Node
The walls of Room would be the edges (Edge class?)
We will use a BFS approach here as it gives O(n) complexity for this problem

class Door{
Room next;
int keyId;
}
class Room{
int keyId=-1;
boolean has_treasure = false;

Room(int keyId){
    this.keyId = keyId;
    has_treasure = false;
} 

}

I am struggling to formulate the code from scratch, any help with code is appreciated

Found some problem doscussion here
https://www.careercup.com/question?id=5097647948955648#:~:text=You%20are%20a%20game%20developer%20working%20on%20a%20game%20that,opened%20by%20a%20unique%20key.

Comments (0)