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: Practice | GeeksforGeeks | A computer science portal for geeks

Link to the code: Online Compiler and IDE - GeeksforGeeks
If the above given link doesn’t work, try this SPIDEY SENSE - Pastebin.com

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