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
4mo
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...
Microsoft Corporation Software Developer interview questions & answers
A Software Developer was asked 8mo agoQ. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 8mo agoQ. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0'...read more
A Software Developer was asked 9mo agoQ. Why do you want to join Microsoft?
Popular interview questions of Software Developer
A Software Developer was asked 8mo agoQ1. Given an integer array nums and an integer k, return the kth largest element in ...read more
A Software Developer was asked 8mo agoQ2. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0'...read more
A Software Developer was asked 9mo agoQ3. Why do you want to join Microsoft?
>
Microsoft Corporation Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

