Pregunta de entrevista de Meta

It was a BFS problem.