Prepin
Log in

I encountered a coding problem titled "finding Alibada." The concept involves a set of rooms, with Alibada located in one of them. He moves to an adjacent room each day. You are provided with a list of rooms, and your task is to programmatically ascertain whether you can locate Alibada using this list.

Approach / Explanation

This question focuses on graph traversal within the realm of algorithmic problem-solving . The scenario involves a fictional character named Alibada, who occupies one of several rooms and moves to an adjacent room each day that shares a boundary (or tangent). Given a list of rooms as input, your task is to develop a solution that can programmatically ascertain whether Alibada can be located. In essence, this is a problem of navigating through a graph of rooms to determine if Alibada can be reached. You might consider employing either Breadth-First Search (BFS) or Depth-First Search (DFS) algorithms to investigate the rooms. In this context, the rooms represent the nodes, and the tangents connecting them signify the edges. The key points to remember when addressing this problem are: Utilize BFS or DFS to navigate through the rooms. Comprehend the structure of the graph or the list of rooms provided as input. Develop a mechanism to keep track of visited rooms to prevent redundant checks.

Suggested Answer

One method for addressing this issue involves utilizing the DFS algorithm, which can be represented in pseudocode as follows: function find_alibada(rooms, startRoom): initialize a stack and push the starting room onto it create a list to track rooms that have been visited while the stack is not empty: currentRoom = remove the top room from the stack if currentRoom has Alibada: return True for each room adjacent to currentRoom: if this room has not been visited: mark this room as visited push this room onto the stack return False # if the loop concludes without locating Alibada This function will yield True if Alibada is reachable from the starting room; otherwise, it will return False .

Alternative Answer

Another potential solution employs the BFS approach, which can be summarized as follows in pseudocode: function find_alibada(rooms, startRoom): create a queue and add the starting room to it create a list to track visited rooms while the queue is not empty: currentRoom = remove the front room from the queue if currentRoom has Alibada: return True for each room adjacent to currentRoom: if this room has not been visited: mark this room as visited add this room to the queue return False # if the loop finishes without finding Alibada Similar to the earlier example, this function will return True (if Alibada is found) or False (if Alibada is not found).

Question Details

Difficulty & Category

Medium
algorithms

Companies

Meta (Facebook)

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.