Infosys Interview Question

graph question based on traversals like bfs and dfs