Google interview question

algorithm problem can be solved with dfs