Everyone Under a Manager
Problem statement
A company table has one row per person: row i says that employees[i] has manager managers[i] and earns salaries[i]. A person at the top of the company has the empty string as manager.
Given the name manager, return everyone who works under that person: their direct reports, the people who report to those, and so on down. Do not include manager. Return the names sorted in alphabetical order (an empty list if nobody works under them). The salary column is part of the table but is not needed for this question.
Function
allReports(employees: String[], managers: String[], salaries: int[], manager: String) → String[]Examples
Example 1
employees = ["Ravi","Mia","Lena","Omar","Kai"]managers = ["","Ravi","Mia","Mia","Ravi"]salaries = [300,200,120,110,150]manager = "Mia"return = ["Lena","Omar"]Lena and Omar report to Mia directly. Nobody reports to Lena or Omar, so the answer is ["Lena", "Omar"] in alphabetical order.
Example 2
employees = ["Ana","Ben","Cy","Dee"]managers = ["Cy","Ana","","Ben"]salaries = [90,80,100,70]manager = "Cy"return = ["Ana","Ben","Dee"]Ana reports to Cy, Ben reports to Ana, and Dee reports to Ben, so all three are under Cy, directly or through others: ["Ana", "Ben", "Dee"].
Example 3
employees = ["Zed","Yan"]managers = ["","Zed"]salaries = [500,400]manager = "Yan"return = []Nobody reports to Yan, so the answer is an empty list.
Constraints
1 <= employees.length <= 2000, andmanagersandsalarieshave the same length asemployees- each name is 1 to 12 English letters, an uppercase letter followed by lowercase letters, and the names in
employeesare all different - each
managers[i]is either""(no manager) or a name inemployees, and following managers upward from anyone always ends at a person with no manager 1 <= salaries[i] <= 10^6manageris a name inemployees