Amazon Interview Question

simple question bfs find distances