Problem · Hash Table
Inherited Role Permissions
Learn this problemProblem statement
A role may inherit from one parent role. Each role has an allow list and a deny list of permission names. A child role inherits decisions from its ancestors, but the nearest explicit decision overrides every decision higher in the hierarchy.
For the requested role and permission:
- Starting at
role, walk toward the root. - If the current role explicitly denies the permission, return
false. - If the current role explicitly allows the permission, return
true. - If no role in the chain mentions the permission, return
false.
The arrays roles, parents, allowLists, and denyLists are aligned by index. A root role has the empty string as its parent. A role never contains the same permission in both of its own lists.
Function
hasPermission(roles: String[], parents: String[], allowLists: String[][], denyLists: String[][], role: String, permission: String) → booleanExamples
Example 1
roles = ["employee","engineer","intern"]parents = ["","employee","engineer"]allowLists = [["read"],["deploy"],[]]denyLists = [[],[],["deploy"]]role = "intern"permission = "deploy"return = falseThe intern's explicit deny overrides the engineer's inherited allow.
Example 2
roles = ["employee","engineer","intern"]parents = ["","employee","engineer"]allowLists = [["read"],["deploy"],[]]denyLists = [[],[],["deploy"]]role = "intern"permission = "read"return = trueNeither intern nor engineer mentions read, so the permission is inherited from employee.
More Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Root of the Largest TreePHONE SCREEN · Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Cheapest Flights Within K StopsONSITE INTERVIEW · Seen Jun 2026
- Word LadderPHONE SCREEN · Seen Jun 2026
- Log Buffer AnalyzerOA · Seen May 2026