How to solve this question using Recursion

Problem Link:- PrepBytes