Back to problems

Merge N-ary Tree

Algorithm · LinkedIn · Medium

Merge N-ary Trees Easy (This problem is a variation of LeetCode 617. Merge Two Binary Trees; solving that simpler version first is recommended.) Write a function merge_trees(tree1, tree2) that merges two n-ary trees into a new tree. Each node stores an integer value and a list of child nodes; during the merge children are aligned by their index in the children list. The merging rules are: When both trees have a node at the same index, create a merged node whose value is the…

Checking your access…