Check Graph Reachability For File Permissions
FigmaSoftware Engineer · Technical ScreenLast updated
Practice graph reachability for simplified file-permission inheritance under directed, undirected, and blocked-edge variants. The prompt is useful for reviewing DFS or BFS, visited sets, cycle handling, and clarifying traversal semantics.
You are given a graph representing simplified file permission inheritance. In part 1, the graph is directed and may contain cycles. Return whether there is a path from source to destination. In part 2, treat relationships as bidirectional and answer the same query. In part 3, support a set of blocked edges that cannot be used during traversal.
Function signature:
def has_path_directed(n: int, edges: list[tuple[int, int]], source: int, destination: int) -> bool:
pass
def has_path_undirected(n: int, edges: list[tuple[int, int]], source: int, destination: int) -> bool:
pass
def has_path_with_blocked_edges(n: int, edges: list[tuple[int, int]], blocked: set[tuple[int, int]], source: int, destination: int) -> bool:
pass
Constraints:
0 <= source, destination < n.- The graph may contain cycles.
- Use BFS or DFS with a visited set.
- For blocked edges in an undirected traversal, clarify whether both directions are blocked.
Examples:
n = 3, edges = [(0,1),(1,2)], source = 0, destination = 2
Directed output: True
n = 3, edges = [(1,0)], source = 0, destination = 1
Directed output: False; undirected output: True
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.