Implement an employee directory that returns the deepest group containing every employee in a query. A group contains its direct employees and all employees in its descendant groups. The deepest group is the one farthest from the root.
EmployeeDirectory(String rootGroupId, List<String> groupRelations, List<String> employeeMemberships)
rootGroupId: The root group's ID.groupRelations: Each string is "parentGroupId,childGroupId". Group IDs come from these relations and rootGroupId.employeeMemberships: Each string is "employeeId,groupId", assigning an employee to an existing group.String getCommonGroupForEmployees(List<String> employeeIds)
"" if the query is empty or any requested employee does not exist.1 to 100,000. The number of group relations is one less than the number of groups.1 to 100,000.0 to 100,000.Discuss these independent extensions to the tree version. The empty-query, unknown-employee, and duplicate-ID rules still apply.
String.compareTo. Return "" if no common group exists.String.compareTo among groups containing every requested employee, or "" if none qualify.Named arguments and bracketed lists below are pseudocode. All queries use this directory:
EmployeeDirectory(
rootGroupId = "org",
groupRelations = ["org,technology", "org,finance", "technology,services", "technology,apps", "services,storage", "finance,payroll"],
employeeMemberships = ["e1,storage", "e2,storage", "e3,services", "e4,apps", "e5,payroll", "e6,org"]
)
getCommonGroupForEmployees(employeeIds = ["e1", "e2"])"storage". Both employees belong directly to storage.getCommonGroupForEmployees(employeeIds = ["e1", "e3"])"services". Services directly contains e3 and contains e1 through storage.getCommonGroupForEmployees(employeeIds = ["e1", "e3", "e4"])"technology". Technology contains employees in both services and apps.getCommonGroupForEmployees(employeeIds = ["e2", "e5"])"org". The employees are in different branches of the root.getCommonGroupForEmployees(employeeIds = ["e1", "e6"])"org". Employee e6 belongs directly to the root.getCommonGroupForEmployees(employeeIds = ["e4"])"apps". A single employee's direct group is returned.getCommonGroupForEmployees(employeeIds = ["e1", "e1"])"storage". Repeated IDs are ignored.getCommonGroupForEmployees(employeeIds = [])"". The query is empty.getCommonGroupForEmployees(employeeIds = ["e1", "missing"])"". Employee missing does not exist.