Solution: Find Minimum Diameter After Merging Two Trees
Understand how to apply the tree breadth-first search (BFS) pattern to find the diameter of two trees and determine the minimal possible diameter after connecting them with one edge. Learn the step-by-step BFS passes to find farthest nodes and apply a formula that connects tree centers to minimize the combined diameter efficiently.
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 one node from the second tree using a ...