Google Interview Question

Graph dfs and bfs problem