I spent the first few minutes trying to build an actual tree structure and got tangled up pretty fast.
Clarify the input format and edge cases, then propose building a tree from the domain hierarchy. Traverse the tree to identify leaf domains and accumulate scores from ancestors present in the input, finally sorting the results lexicographically.
Pro tip: Mention that you would validate the input for cycles or invalid domains, and discuss how to handle large inputs efficiently with iterative traversal to avoid recursion limits.
Ask about input size, domain format, possible duplicates, and whether scores can be negative. Confirm that leaf domains are those with no children in the input set.
Construct a tree or graph where each domain points to its parent (by removing the leftmost label). Use a hash map to store domain-score pairs for quick lookup.
Traverse from each domain up to its ancestors, summing scores of those present in the input. Alternatively, do a DFS from roots, propagating cumulative sums, and collect leaves.
Collect all leaf domains with their cumulative scores, sort lexicographically by domain name, and return the sorted list.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.