Topmost Accessible Nodes
Updated
Problem statement
A hierarchy contains teams, folders, and files. It is represented as a forest of nodes.
nodeIds[i]is the unique ID of nodei.parent[i]is the parent index, or-1when nodeiis a root.readableUsers[i]lists the users with direct read access to nodei.
Direct access to a node also grants access to every descendant. For userId, return the smallest covering set of nodes: whenever the user has direct access to a node, include that node and do not include any accessible descendant beneath it.
Return selected node IDs in forest preorder. Roots and siblings follow their order in the input arrays.
Function
fewestAccessibleNodes(nodeIds: String[], parent: int[], readableUsers: String[][], userId: String) → String[]Examples
Example 1
nodeIds = ["Team1","Folder1","File1","File2","Folder2","Folder3"]parent = [-1,0,1,1,0,4]readableUsers = [[],["A"],["A"],[],[],["A"]]userId = "A"return = ["Folder1","Folder3"]Folder1 covers both files beneath it, so File1 is redundant. Folder3 is in another branch and is also required.
Example 2
nodeIds = ["Team1","Folder1","File1","Folder2"]parent = [-1,0,1,0]readableUsers = [["A"],["A"],["A"],[]]userId = "A"return = ["Team1"]Access at the root covers every descendant, so it is the only selected node.
Example 3
nodeIds = ["RootA","LeafA","RootB","LeafB"]parent = [-1,0,-1,2]readableUsers = [[],["U"],[],["U"]]userId = "U"return = ["LeafA","LeafB"]Neither root grants access, so each directly readable leaf must be returned.
Constraints
1 <= nodeIds.length <= 200000.nodeIds.length == parent.length == readableUsers.length.- Node IDs are unique.
- For every non-root node
i,0 <= parent[i] < i. - The total number of direct user entries is at most
200000.
More Figma Phone Screen questions
- Recursive Display SortPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Route Graph Reachability with a Broken LinkPHONE SCREEN · Seen Oct 2026
- Rich Text Parser Part 3 (Depth Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 2 (Parse Nested Groups)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Rich Text Parser Part 1 (Validate Tokens)PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Layer History with Batch Undo and RedoOA · PHONE SCREEN · Seen Sep 2026
- Table Selection and Color UpdatesPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Intersection of Two RectanglesPHONE SCREEN · Seen Aug 2024
- Sparse Canvas Paint HistoryPHONE SCREEN · Seen Sep 2023
- Shell Path AutocompletePHONE SCREEN · ONSITE INTERVIEW · Seen May 2022
Similar questions at other companies
- Render an Org Chart and Find Skip-Level PairsSnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Delete Nodes and Return Forest RootsGoogle · ONSITE INTERVIEWGoogle interview questions
- Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
- JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
- Merge N-Ary Trees by KeyLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Render a Stable Comment HierarchyBobyard · PHONE SCREEN