Google interview question

A recursive problem. It takes me sometime to explain my coding.