Google interview question

Algorithm problem about DFS and backtracking