Goldman Sachs Interview Question

How would you solve this recursively?