Google Cloud Interview Question

They asked me to solve a dfs tree traversing