Question d’entretien chez Google

algorithm problem can be solved with dfs