Pregunta de entrevista de Yelp

Pretty straightforward BFS graph question