Your question is Print Company Hierarchy. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Hulu needs a readable representation of its employee reporting structure. Given each employee and their direct manager, format the hierarchy from the top-level leader downward.
Implement format_hierarchy(employees). The input is a dictionary mapping an employee name to their manager's name. The single root employee maps to None. Return one string containing one employee per line, in preorder traversal. Indent each reporting level with two spaces. Preserve the order in which employees appear in the input dictionary when listing peers.
The function should not print directly, because returning the formatted string makes the result easier to test. A caller can print the returned value.
def format_hierarchy(employees):