Pregunta de entrevista de Amazon

Medium/Hard level graph traversal Leetcode Question