Pergunta de entrevista da empresa Bloomberg

algorithm question about tree backtracking