What is the wrong in my code?

I am trying to solve the question from today’s GeeksForGeeks Hiring Challenge 2020.

The Question is SPIDEY SENSE and i have used simple dfs traversal.
Sample test cases are passed. But when i submit the code it is showing WA?

Could you please tell the wrong in my code? Thanks in Advance :slight_smile:

Link to the Question: https://practice.geeksforgeeks.org/contest-problem/spidey-sense/0/

Link to the code: https://ide.geeksforgeeks.org/KLyBJZcTTd
If the above given link doesn’t work, try this https://pastebin.com/yThgpd8g

2 Likes

Thanks a lot @galencolin. I am happy because i have learned that DFS cannot give always a shortest path in an unweighted graph. I will implement it using BFS and get back to you if it does not work.

Hurrah! It worked.

1 Like