Search
⌘K

Leetcode 617. Merge Two Binary Trees

Given two binary trees, merge them into a new tree by traversing both from the roots and summing the values of overlapping nodes while using the non-null node when one side is missing. This is typically solved with a simultaneous DFS/BFS traversal (often recursive) that combines corresponding nodes.

Asked at:

Google

Google


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Late September, 2024

Google

Google

Mid-level

Merge two n-ary trees. Given roots of 2 n-ary trees, write code to merge them following specific rules: 1) If nodes have the same name at the same level, combine their children and use the value from the second tree. 2) If a node has no corresponding match, add it directly. 3) Preserve the order of nodes based on their original position in both trees.

Comments

Your account is free and you can post anonymously if you choose.