Find Minimum Diameter After Merging Two Trees
Try to solve the Find Minimum Diameter After Merging Two Trees problem.
We'll cover the following
Statement
You are given two undirected trees: one with edges1
of length edges2
of length edges1[i] = [aᵢ, bᵢ]
represents an edge between nodes edges2[i] = [uᵢ, vᵢ]
represents an edge in the second tree.
Your task is to connect any node from the first tree to any node from the second tree using a single edge. Return the smallest possible diameter of the resulting combined tree.
Note: The diameter of a tree is the length of the longest path between any two nodes in it.
Constraints:
edges1.length
edges2.length
edges1[i].length
edges2[i].length
edges1[i] = [a
i
, b
i
]
edges2[i] = [u
i
, v
i
]
The
edges1
andedges2
always represent valid trees.
Examples
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.