Inherited Role Privileges
Asked at Snowflake
Reported by the problem's creator, not verified
A company models access rules as roles. You are given a class RoleGraph whose constructor takes n, the number of roles numbered 0 to n - 1, and grants, a list of [parent, child] pairs meaning child inherits from parent. The grants form a directed acyclic graph, and a role may have several parents. Inheritance is transitive: a role inherits from its parents' parents too.
Privileges are lowercase strings. effective(allow) takes a list of length n, where allow[i] lists the privileges assigned directly to role i, and returns one list per role.
Each test constructs one RoleGraph and calls effective once; the output lists every call's return value.
Examples
Example 1
Input: init =
[4,[[0,1],[1,2]]], operations =[["effective",[[["a"],["b"],["c"],[]]]]]Output:
[[["a"],["a","b"],["a","b","c"],[]]]Explanation: Role 1 inherits role 0's
aand addsb; role 2 inherits both and addsc. Role 3 has no grants and no privileges.