Amazon interview question

simple question bfs find distances