Closest Node to Path in Tree
Try to solve the Closest Node to Path in Tree problem.
We'll cover the following
Statement
You are given a positive integer, n
, representing the number of nodes in a tree, numbered from edges
of length edges[i]
You are also given a 2D integer array query
of length query[i]
For each query i
, find the node on the path between
Return an integer array where the value at index
Note: If there are multiple such nodes at the same minimum distance, return the one with the smallest index.
Constraints:
n
edges.length
edges[i].length
query.length
query[i].length
The graph is a tree.
Examples
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.