InterviewDB Experience

Root IDs: Find All Root Nodes in a Forest Given Parent Pointers

Interview Experience

Problem You are given a list of (node_id, parent_id) pairs representing a forest (collection of trees). A root node is one that does not appear as a child of any other node. Return all root node IDs in sorted order. Follow-ups What if the input contains a cycle? How would you detect and report it? How would you reconstruct the full tree structure (children mapping) from this edge list? If node_id values are strings instead of integers, how does your solution change? How would you find all leaf n…

Full Details

🔒

Unlock all Ziphq questions

Full insider details, leaked discussions, and candidate experiences.

Get full access — $100 a year, unlimited access

About This Question

This is a candidate experience report from a ziphq interview during the phone round.

It covers the following topics: Coding, Phone, Onsite, Strings .