Infosys interview question

Coding question for a pattern with recursive nature