Amazon Interview Question

Given a list of structs which include two ids of parent node and the associated child node, construct a tree.

Interview Answer

Anonymous

Jun 25, 2011

The solution should use O(n) time and O(n) space. The idea is to hash ids (parent id - child id). The the linear scan constructs the tree.