Description
Prompt
Implement file system permissions management. You need to handle three data structures: Teams, Folders, and Files.
- Each team, folder, and file has a list of user IDs indicating who can access it.
- If a user can access a higher-level team/folder/file, they can also access all nested subfolders/files.
APIs
init(teams, folders, files): Initialize and store the structures.get_fewest(user_id): Return the fewest teams/folders/files that cover all resources the user can access (i.e., the highest-level nodes granting access).
Example
Team1
/
Folder1(A) Folder2
/ \ |
file1(A) file2 Folder3(A)
For user A, return [Folder1, Folder3] as the minimal set of top-level nodes covering their access.
Constraints
init()does not return data; it stores state.user_idsprovided as lists; access checks should be efficient.- Aim for memory- and performance-aware design; consider up to thousands of nodes.
Notes
- System design / data-structure design; phone screen level.
Discussion (0)
All comments are anonymous. Your identity is not shared.
Loading comments...
Loading editor…
OUTPUTLast run results appear here.
No output yet. Click "Run Code" to see results.