Problem Brief
Find Minimum Possible Diameter
OA
See Google online assessment and hiring insights
You are given a tree consisting of n vertices.
You can perform the following operation at most k times: delete a single leaf of the tree (the operation can produce new leaves, that can be deleted later). The resulting tree must have as small diameter as possible. Find the minimum possible diameter.
Input Format
The first line contains two space separated integers n and k. Each of the next n-1 lines contains two space separated integers, describing the current tree edge. It's guaranteed that the given graph is a tree.
Constraints
0 < n <= 1e5
0 < k < n
1Example 1
Input
n = 4, k = 0, edges = [[1, 2], [2, 3], [4, 3]]
Output
3
Explanation
:3
2Example 2
Input
n = 4, k = 1, edges = [[2, 3], [4, 3], [1, 4]]
Output
2
Explanation
:o