Pregunta de entrevista de Two Sigma

Some recursion problem, likely leetcode hard