Build reporting trees from employee-manager pairs
You get a list of [employee, manager] pairs, where each person is a positive integer id and the pair means the employee reports directly to that manager. Build the org chart top-down: every manager who reports to nobody is the root of a tree, and each person's children are their direct reports. Return the forest (for example as nested structures or a printed outline).
Discuss how you find the roots, how you order children, and what you do with bad input such as a person with two managers or a reporting cycle.
No answer yet. Write the first one; the best answer gets endorsed.
