← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given a role table in a company organization where every employee has a role. The role table consists of a unique string role and a unique string privilege. The company has a hierarchical structure, meaning each role inherits the privileges of its parent role, and each role can have only one parent.
Write an API:
void init(PrivilegeRoles privileges): Initializes the system with a list of roles and the privileges they inherit from.List<String> roleInheritance(String role): Returns a list of roles that directly or indirectly inherit the privileges of the given role. The returned list should exclude the given role itself.1 <= privileges.length <= 10^51 <= privileges[i].parent.length <= 101 <= privileges[i].child.length <= 10privileges[i].parent != privileges[i].childparent and child consist of lowercase English letters.roleInheritance, the given role must exist in the system.Input:
privileges = [ ["role1", "role2"], ["role2", "role3"], ["role3", "role3"], ["role3", "role4"] ] role = "role2"
Output:
["role3", "role4"]
Explanation:
role2` has the direct privilege of `role2`, and indirectly inherits `role3` and `role4`.
`
### Example 2:
**Input:**
`
privileges = [
["role1", "role2"],
["role2", "role3"],
["role2", "role4"]
]
role = "role1"
`
**Output:**
`
["role2", "role3", "role4"]
`
**Explanation:**
`
role1` has the direct privilege of `role1`, and indirectly inherits `role2`, `role3`, and `role4`.