← Problems64. Effective folder permissionsMediumPython
00:00 / 30:00

Effective folder permissions

MediumNot attempted yetAsked at Adobe

An asset library nests folders arbitrarily deep and grants roles at any level. A grant is inherited by everything beneath it, and the strongest role a principal picks up anywhere on the path wins — a weaker grant nearer the folder does not override a stronger one further up.

Input schema

solve(folders: list[dict], grants: list[dict]) -> list[dict]

Each folder has folder_id (int), parent_id (int or None for a root) and name (str). Each grant has folder_id (int), principal (str) and role, one of VIEWER, EDITOR or OWNER, in increasing strength.

Return one dict per folder and principal with any effective role, keys in this order:

folder_id, principal, role

Constraints

  • A principal's effective role on a folder is the strongest granted on it or any ancestor
  • Distance does not matter: OWNER at the root beats VIEWER granted on the folder itself
  • A folder with no grant anywhere above it contributes no rows
  • Several grants for one principal on one folder collapse to the strongest
  • Order by folder_id, then principal
  • Up to 500,000 folders and 2,000,000 grants

Example 1a root grant reaches the leaf

Input · grants
rolefolder_idprincipal
EDITOR1ana
Input · folders
namefolder_idparent_id
root1null
brand21
logos32
Output
folder_idprincipalrole
1anaEDITOR
2anaEDITOR
3anaEDITOR

Example 2an unreached folder contributes nothing

Input · grants
rolefolder_idprincipal
VIEWER2bo
Input · folders
namefolder_idparent_id
root1null
shared21
private5null
Output
folder_idprincipalrole
2boVIEWER

Topics

tree traversaldata structures

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.py
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8⌘↵ run ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.