Amazon | OA | find the least common manager for two employees
Anonymous User
311

Given a company hierarchy, find the least common manager for two employees.

There is a company which has a CEO and a hierarchy of employees.
All employees have a unique ID, name and a pointer to their manager and their reports.
Please implement the commonManager() method to find the closest manager for two given employees
(i.e. the manager farthest from the CEO that both employees report up to).

class Employee {
    long id; // unique ID
    String name; // name (not unique)
    Employee manager; // null for CEO
    Set<Employee> reports; // empty set for a non-manager
}
Comments (1)