Pregunta de entrevista de Amazon

First question was leetcode medium involving graphs