Pergunta de entrevista da empresa Lyft

BFS/dfs related question, was difficult