Pergunta de entrevista da empresa Toast Inc

Technical question involving BFS/DFS