How to check if particular node exist between source and destination in a bidirectional graph
Perform a bfs form src node. Maintain a parent array storing each node’s parent. When you reach destination node. Terminate the bfs. Now follow the destination to src path using parent array if that particular node found then answer if True else False.
If there are lot of queries @grey_hat_geek
Why not just link to the full Problem?
It was a hiring contest link is not available
If there are a lot of queries, I guess finding components in the graph might be helpful. You can find different components and maintain an array that will tell you the component it belongs to.
Now if source node, destination node and node to be checked all lies in same component,
return 1 else return 0.
Not sure, but this should work in case of multiple queries.
Can you post the quesiton link ?