ZapCom Group interview question

Recursive programming coding on the example given