The direct report count was easy, just build an adjacency list and you're done.
Clarify the input format and requirements, then propose building a tree from the manager-report pairs and using DFS to compute subtree sizes. Precompute a map from each person to their role, direct report count, and total report count for O(1) lookups.
Pro tip: Mention that you can compute all values in one pass with memoization or post-order traversal, and discuss handling edge cases like multiple roots or cycles to show robustness.
Ask about input size, whether the org chart is a tree (single root, no cycles), and if lookUp should handle unknown names. Confirm the expected output format.
Build an adjacency list mapping each manager to their direct reports, and a set of all people. Identify the root(s) by finding who never appears as a direct report.
Perform a post-order DFS from the root(s) to compute for each node: role (IC if no children, else Manager), direct report count (number of children), and total report count (sum of children's total reports + direct reports).
Store the computed metrics in a hash map for O(1) retrieval. If lookUp is called with an unknown name, return null or throw an error as appropriate.
State that preprocessing takes O(N) time and space, and each lookUp is O(1). Walk through a small example to verify correctness, including edge cases like a single node or deep hierarchy.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.