Hyperscience Interview Question

Programming problem about BFS and DFS