Please help me with this question from starter div-3

I am getting WA fot this question . I think its a simple BFS implementation.
Here is the question. please help me to point out mistake in my approach. Here is my solution.