Pregunta de entrevista de Toast Inc

Technical question involving BFS/DFS