Doubt in the logic

Sir, I have doubt as to where to initialise any variable in the recursive function.
I earlier solved the question in the following way which I have commented out. I get confused where to initialise variables .

Hello @vageesha i have commented the explanation here: