Goldman Sachs interview question

How would you solve this recursively?