Google interview question

Abstract Problem boiling down to DFS