Pergunta de entrevista da empresa Amazon

Question which could be represented as a graph, and the solution involved implementing bfs to arrive at the answer