Domanda di colloquio di Publicis Sapient

basic algorithmic question, based on dfs.