Pergunta de entrevista da empresa Publicis Sapient

basic algorithmic question, based on dfs.