← 返回 goldmansachs 的题目列表Role-Based Permission Resolution with Inheritance
类型:online_judge
Implement getPermission(role) to compute the effective permissions of a role.
Each role contains:
parents: a list of parent role names;
allow: a set of explicitly allowed permissions;
deny: a set of explicitly denied permissions.
Permissions are strings such as read, write, and delete.
Rules:
A child role inherits the effective permissions of all parents;
Explicit settings on the current role override inherited settings;
Within the same role, deny takes precedence over allow;
With multiple parents, merge inherited results; if one parent allows a permission and another denies it, denial wins;
The inheritance graph is guaranteed to be acyclic.
Return the final allowed permission set in lexicographic order.
Input Format
The first line contains integer n, the number of roles.
Each of the next n lines has the format:
role_name parent1,parent2|- allow1,allow2|- deny1,deny2|-
- denotes an empty list.
The last line contains the role to query.
Example
Input:
3
viewer - read -
editor viewer write -
restricted editor - write
restricted
Output:
read
Example
Input
3
viewer - read -
editor viewer write -
restricted editor - write
restricted
Output
read