Two Sigma Interview Question

Some recursion problem, likely leetcode hard