Practice Find Minimum Diameter After Merging Two Trees
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Find Minimum Diameter After Merging Two Trees
Problem Statement
There exist two undirected trees with n and m nodes, numbered from 0 to n - 1 and from 0 to m - 1, respectively. You are given two 2D integer arrays edges1 and edges2 of lengths n - 1 and m - 1, respectively, where edges1[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the first tree and edges2[i] = [ui, vi] indicates that there is an edge between nodes ui and vi in the second tree. You must connect one node from the first tree with another node from the second tree with an edge. Return the minimum possible diameter of the resulting tree. The diameter of a tree is the length of the longest path between any two nodes in the tree.
Source: Find Minimum Diameter After Merging Two Trees on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
edges1 = [[0,1],[0,2],[0,3]], edges2 = [[0,1]]
3
# Example 2
edges1 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]], edges2 = [[0,1],[0,2],[0,3],[2,4],[2,5],[3,6],[2,7]]
5
Constraints
Related LeetCode Problems
Practice more problems similar to Find Minimum Diameter After Merging Two Trees.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.