Pregunta de entrevista de Workday

something could be solved with bfs