Amazon Interview Question

traditional bfs, dfs algo question