Back to problems

Travese and Merge Two N-ary Trees

Algorithm · Hudson River Trading · Easy

An N-ary tree is encoded as a list named nodes. Each row in nodes describes exactly one node: nodes[i][0] is the node's key. nodes[i][1] is the node's value. Any remaining entries, nodes[i][2...], give the row indices of the node's children in left-to-right order. The rows are not required to appear in any particular order. They are guaranteed to represent exactly one valid tree, and that tree has a unique root. Child ordering matters. For a single parent, its children have…

Checking your access…