Hackerrank - BFS problem