FastPrepEveryone Under a Manager
Problems/Everyone Under a Manager

Everyone Under a Manager

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem returns, in alphabetical order, everyone who works under a given manager, directly or through other managers, from a table of employee, manager and salary rows. An Adobe MTS-2 report gives this as its first-round problem in one sentence, says the author walked the hierarchy breadth-first, and lists follow-up talk on trees versus graphs.

Our choices: indirect reports count too, the manager is not listed, names are unique, a top-level person has an empty manager name, the salary column is present but unused, the answer is sorted by name, at most 2000 rows, and new examples.

The judged task matches the report at about 80%.

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, and managers and salaries have the same length as employees
  • each name is 1 to 12 English letters, an uppercase letter followed by lowercase letters, and the names in employees are all different
  • each managers[i] is either "" (no manager) or a name in employees, and following managers upward from anyone always ends at a person with no manager
  • 1 <= salaries[i] <= 10^6
  • manager is a name in employees

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public String[] allReports(String[] employees, String[] managers, int[] salaries, String manager) {
    // Write your code here.
}
Checking account…