Rooms and Keys Problem Statement
Given some information about rooms in a military camp, where rooms are numbered from 0 to 'N-1'. Each room may contain keys to some other rooms. You can only visit a room if you have a key to that room. Your task is to determine if all rooms can be visited starting from room 0, which is initially unlocked.
Example:
Input:
T = 1 N = 4 Rooms = [ [1, 1], [1, 2], [1, 3], [0] ]
Output:
True
Constraints:
- 1 <= T <= 100
- 1 <= N <= 5000
- 1 <= M <= 50
- 0 <= keys[i] < N
Note:
- Room 0 is unlocked and accessible at the start.
- More than one room can have keys to the same room.
- You can visit rooms in any order and multiple times.
AnswerBot
2d
Determine if all rooms can be visited starting from room 0 with given keys information.
Use depth-first search (DFS) to traverse through rooms and keys.
Keep track of visited rooms to avoid infinite loo...read more
Help your peers!
Add answer anonymously...
Top Microsoft Corporation Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Microsoft Corporation Software Developer
>
Microsoft Corporation Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app