Pregunta de entrevista de Amazon

One coding question based on DFS