Pregunta de entrevista de Standard Chartered Bank

graph question based on dfs.