File Permission Reachability
Asked at Figma
Reported by the problem's creator, not verified
A file-sharing product models access inheritance as a directed graph. Nodes are numbered 0 to n - 1. An edge [a, b] means access held on a is inherited by b. The graph may contain cycles, self loops and repeated edges.
Build a class PermissionGraph(n, edges) that answers reachability queries. A node always reaches itself. Each test creates one graph and then issues every query against it; each query returns a boolean.
Examples
Example 1
Input: init =
[3,[[0,1],[1,2]]], operations =[["reachable",[0,2]],["reachable",[2,0]],["reachable",[0,1]],["reachable",[1,0]],["reachable",[1,1]],["reachable",[2,2]]]Output:
[true,false,true,false,true,true]Explanation: Access flows along the edges, so 0 reaches 1 and 2, and 1 reaches 2. Nothing flows backward, so 2 cannot reach 0 and 1 cannot reach 0. Every node reaches itself.