Amdocs interview question

String traversal using bfs and dfs