Pergunta de entrevista da empresa Two Sigma

Some recursion problem, likely leetcode hard