← Bloomberg Interview Insights

Bloomberg·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Bloomberg SWE interview with a tree problem that sounds easy until you actually think through all the edge cases. Decent question, left me second-guessing my complexity analysis afterward.

Questions Asked (1)

Q1

You're given an unordered list of nodes, each with an id and a set of child ids (no parent pointers). Find the root of the n-ary tree. Also explain your algorithm, data structures, time/space complexity, and how you'd handle invalid inputs like multiple roots, cycles, or missing node references.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was just 'collect all child ids into a set, then find whichever node id isn't in it, that's your root.' Which is right, but they kept pushing on the validation side and I fumbled a bit there.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose an efficient algorithm using a hash set to track all child ids. The root is the node whose id is not in the child set. Discuss how to detect invalid inputs such as multiple roots, cycles, or missing references, and analyze time/space complexity.

Pro tip: Mention that you can detect cycles by verifying that the number of nodes equals the number of edges plus one (for a tree) or by performing a traversal from the root. This shows thoroughness and understanding of tree properties.

1. Clarify requirements and edge cases

Ask if the tree is guaranteed to be valid, if node ids are unique, and if the list can be empty. Discuss how to handle invalid inputs like multiple roots, cycles, or missing references.

2. Propose algorithm

Explain that you will collect all child ids into a hash set, then iterate through nodes to find the one whose id is not in the set. That node is the root.

3. Analyze complexity

State that time complexity is O(n) where n is number of nodes, and space complexity is O(n) for the hash set. Mention that this is optimal since you must examine each node at least once.

4. Handle invalid inputs

Describe how to detect multiple roots (more than one node not in child set), cycles (e.g., using DFS or checking edge count), and missing references (child id not present in node list).

5. Test with examples

Walk through a simple example and an invalid case to demonstrate correctness and error handling.

Key Points to Mention

  • Use a hash set for O(1) lookups to track child ids.
  • Root is the only node not appearing as a child.
  • Time complexity O(n), space complexity O(n).
  • Multiple roots: more than one node not in child set.
  • Cycle detection: either via DFS or by checking that edges = nodes - 1.
  • Missing node references: child id not found in the node list.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.