Ezvor

2277. Closest Node to Path in Tree

HardArray Preparing judge… LeetCode
ArrayTreeDepth-First SearchBreadth-First Search

Hints

Hint 1
For the ith query, find the distance from node_i to every other node in the tree.
Hint 2
We can use a BFS to find the distances.
Hint 3
Use DFS to find all the nodes on the path from start_i to end_i.