The Find Minimum Diameter After Merging Two Trees interview question is a high-level graph theory problem. You are given two separate trees and you must add exactly one edge to connect them into a single tree. Your objective is to choose the connection points such that the "diameter" (the longest path between any two nodes) of the resulting merged tree is as small as possible.
Companies like Google and ServiceNow use the Find Minimum Diameter After Merging Two Trees coding problem to test a candidate's mastery of tree properties. It requires understanding tree centers, radii, and diameters. It evaluates whether you can combine multiple Tree interview patterns—such as finding the longest path and the "midpoint" of a tree—to solve a global optimization task.
This problem relies on Breadth-First Search (BFS) or Depth-First Search (DFS) to find tree diameters and centers.
Tree 1 has a diameter of 4 (Radius 2). Tree 2 has a diameter of 2 (Radius 1).
Master the "Two BFS" technique for tree diameters: BFS from an arbitrary node to find the farthest node , then BFS from to find the farthest node . The distance is the diameter. This is a core Graph interview pattern for tree-based metrics.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Frog Position After T Seconds | Hard | Solve | |
| Minimum Fuel Cost to Report to the Capital | Medium | Solve | |
| Maximize the Number of Target Nodes After Connecting Trees II | Hard | Solve | |
| Most Profitable Path in a Tree | Medium | Solve | |
| Tree Diameter | Medium | Solve |