Shikamaru has Queries
My submission
Approach:
I believe finding the shortest path is the answer.
- Perform bfs, starting from source
- For every node visited, store its value in the array
- If destination is found, break the loop.
For a tree with the query and nodes mentioned below, array would be:
1 3 2
1 2
2 3
1 4
4 5
[[1], [1, 2], [1, 2, 3], [1, 4], [5]]
The shortest path to destination should be found at ( destination-1 )th index.
Can anyone help me what is it that I am missing?