2420. Closest Node to Path in Tree

Hard
Array
Tree
Depth-First Search
Breadth-First Search

Description

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.

Statistics

Acceptance
62.3%
Submissions
10,309
Accepted
6,425