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.
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
OWNER at the root beats VIEWER granted on the folder itselffolder_id, then principalgrants| role | folder_id | principal |
|---|---|---|
| EDITOR | 1 | ana |
folders| name | folder_id | parent_id |
|---|---|---|
| root | 1 | null |
| brand | 2 | 1 |
| logos | 3 | 2 |
| folder_id | principal | role |
|---|---|---|
| 1 | ana | EDITOR |
| 2 | ana | EDITOR |
| 3 | ana | EDITOR |
grants| role | folder_id | principal |
|---|---|---|
| VIEWER | 2 | bo |
folders| name | folder_id | parent_id |
|---|---|---|
| root | 1 | null |
| shared | 2 | 1 |
| private | 5 | null |
| folder_id | principal | role |
|---|---|---|
| 2 | bo | VIEWER |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.