Pregunta de entrevista de Amazon Web Services

Graph question using DFS and BFS- Leetcode Hard