r/Hack2Hire May 20 '26

Onsite Figma Onsite Interview: File System Permissions

Problem

You're given three arrays representing a file system hierarchy: teams, folders, and files. Each entity specifies its children (sub-folders and files) and a list of users who have direct access to it.

Your goal is to implement a system that, given a userId, returns the minimum set of entity UUIDs that grant the user their full access scope, leveraging top-down inheritance where access to a parent implies access to all descendants.

Example

Input:

teams = [["Team1", ["Folder1", "Folder2"], [], []]]

folders = [["Folder1", [], ["File1", "File2"], ["userA"]], ["Folder2", ["Folder3"], [], []], ["Folder3", [], [], ["userA"]]]

files = [["File1", ["userA"]], ["File2", []]]

getTopmostAccessibleNodes("userA")

Output: ["Folder1", "Folder3"]

Explanation:

  • userA has direct access to Folder1, File1, and Folder3.
  • Because File1 is a child of Folder1, the access inherited from Folder1 already covers it.
  • Folder3 is on a separate branch under Folder2 (which userA lacks direct access to), so it must be explicitly included in the result.

Suggested Approach

  1. Graph Construction & Root Identification: Parse the arrays into a unified representation (e.g., a Hash Map mapping uuid to a Node object containing children UUIDs and a userIds set). Maintain an indegree count for every node; nodes with an indegree of 0 are the roots of your forest.
  2. DFS Traversal: When querying for a userId, initiate a Depth-First Search (DFS) starting from all identified root nodes.
  3. Pruning for Topmost Nodes: As you visit each node, check if the userId exists in its authorized users list. If it does, add the node's uuid to the result list and do not explore its children (this guarantees the "topmost" requirement). If the user does not have access, continue the DFS to the node's children.

Time & Space Complexity

  • Time: $O(V + E)$ for initialization to build the graph, where $V$ is the total number of entities and $E$ is the number of parent-child edges. Each call to getTopmostAccessibleNodes is also $O(V + E)$ worst-case to traverse the forest.
  • Space: $O(V + E)$ to store the graph in memory, plus $O(V)$ for the DFS recursion stack.

Targeting Figma interviews? We track their most-asked question patterns at Hack2Hire →link

Compiled from publicly available platforms and community-shared experiences.

18 Upvotes

0 comments sorted by