Employee Hierarchy
Asked at Google
Reported by the problem's creator, not verified
You manage a company's reporting structure. Every employee has an integer id and at most one manager. The first employee added, with no manager, is the CEO. Employees are ordered by when they joined: the order of successful add_employee calls. An id that was deleted can be added again later, and then joins as a new employee.
Examples
Example 1
Input: init =
[], operations =[["add_employee",[1,null]],["add_employee",[2,1]],["add_employee",[3,1]],["add_employee",[4,2]],["add_employee",[5,2]],["reports",[1]],["manager_of",[4]],["delete_employee",[2]],["reports",[1]],["reports",[4]],["manager_of",[5]],["delete_employee",[5]],["reports",[4]],["manager_of",[3]]]Output:
[true,true,true,true,true,[2,3],2,true,[3,4],[5],4,true,[],1]Explanation: Employees 4 and 5 report to 2. Deleting 2 promotes 4, who joined first: 4 now reports to 1 and 5 reports to 4.