Page Permission Inheritance
Updated
Problem statement
Permission roles go from lowest to highest in this order: NONE < VIEW < COMMENT < EDIT.
Pages are arranged in one or more trees. Each row of pageParents is [pageId, parentId]. A page with no parent has - as its parent.
A user can get a role in two ways. The first is directly: a row [pageId, userId, role] in userPermissions gives that user the role on that page. The second is through a group. Each group membership is [groupId, userId], and it puts the user in the group. Each group permission is [pageId, groupId, role], and it gives the role on that page to every member of the group.
A permission on a page also applies to every page below it: its children, their children, and so on. A user's effective role on the requested page pageId is the highest role the user gets there. Count the user's direct permissions and group permissions, on that page and on every page above it.
Return two strings:
- the effective role of the requested user
userId; - every user in the permission data whose effective role is above
NONE. Write each one asuserId:role. Sort them by user ID in lexicographic order, which compares the IDs character by character. Join them with commas. If no user qualifies, this string is empty.
Function
resolvePagePermissions(pageParents: String[][], userPermissions: String[][], groupMemberships: String[][], groupPermissions: String[][], pageId: String, userId: String) → String[]Examples
Example 1
pageParents = [["root","-"],["child","root"]]userPermissions = [["root","alice","VIEW"],["child","bob","COMMENT"]]groupMemberships = [["editors","carol"],["editors","alice"]]groupPermissions = [["child","editors","EDIT"]]pageId = "child"userId = "alice"return = ["EDIT","alice:EDIT,bob:COMMENT,carol:EDIT"]Page child sits under root. Alice gets VIEW directly on root, and it passes down to child. She is also in editors, which has EDIT on child. EDIT is higher, so her effective role is EDIT.
Bob has COMMENT directly on child. Carol gets EDIT through editors. All of them are above NONE, so the second string lists them sorted by user ID: alice:EDIT,bob:COMMENT,carol:EDIT.
Constraints
1 <= pageParents.length <= 500.- Every page appears once, parent references are valid, and the page hierarchy has no cycle.
0 <= userPermissions.length, groupMemberships.length, groupPermissions.length <= 2000.- IDs are non-empty ASCII strings containing neither a comma, colon, nor whitespace.
- Every role is one of
NONE,VIEW,COMMENT, orEDIT. - The requested page exists; the requested user need not appear in the permission data.
More Notion interview questions
- Nested Todo ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Mutable Table AggregationsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
- Block Type with the Most ChildrenPHONE SCREEN · Seen Mar 2026
- Country with the Most EventsPHONE SCREEN · Seen Mar 2026
- Event Type with the Most EventsPHONE SCREEN · Seen Mar 2026
- Most Popular Active Plan for the Top Event TypePHONE SCREEN · Seen Mar 2026
- Percentage of Blocks Never EditedPHONE SCREEN · Seen Mar 2026
- Text Document HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Mar 2026
- Versioned Document StorePHONE SCREEN · Seen Apr 2025
- Top Error Types in a Time WindowONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Tree Selection and VisibilityJane Street · PHONE SCREENJane Street interview questions
- Worst-Performing Ads by CTR in a Campaign TreeUber · PHONE SCREENUber interview questions
- Search for an Element in a StreamAmazon · PHONE SCREEN
- Build a File Tree from Streamed RecordsNextdoor · PHONE SCREENNextdoor interview questions
- Hierarchical In-Memory File SystemClay · PHONE SCREEN
- In-Memory File System With Directory SizesCapital One · PHONE SCREEN · ONSITE INTERVIEWCapital One interview questions
- ClayWorkspace Resource TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions