Your question is Role Privilege Inheritance. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
In Snowflake role-based access control, a role inherits all privileges assigned to its ancestor roles. Given each role's directly assigned privileges and direct inheritance grants, compute the complete privilege set for every role.
A grant [parent, child] means the child role inherits the parent's privileges. Return one sorted list of unique privilege names per role, including privileges assigned directly to that role and inherited through any number of ancestors.
Implement calculate_privileges(privileges, grants).
privileges is a list of lists of strings, where privileges[i] contains privileges directly assigned to role i.grants is a list of two-element integer lists. Each [parent, child] represents a direct inheritance relationship.i must contain every privilege role i can receive, sorted lexicographically.The inheritance graph is guaranteed to be a directed acyclic graph, and each role index is valid.
def calculate_privileges(privileges, grants):