i am not getting that if i will use last_digit as a parameter then how will i am gonna pass from main() . Also please explain the recursive call more clearly because i am not getting it from the video.
Recursion solution
Hello @Mrinali_Mangal,
As Sanket Sir has explained in the video you have to count strings ending with 0 and with 1 separately and finally add them to get the desired count.
Thus, you have to make two calls from main:
one with last_digit as 0 and another as 1
Then print the sum of the values returned by both calls.
There is a mistake, you have to return 1 at n==1 because for each digit at n=1 there is only one string.
Now, taking about recursive calls:
Suppose you are at N=2;
…As he said that you have to append 0 at the end of all the strings obtained in N=N-1=2-1=1
so, for n=2 and last_digit=0: it is returning countstring(1,0)+countstring(1,1)=1+1;
and for n=2 and last_digit=1: it is returning countstring(1,0)=1;
adding both the answer will become 3.
Hope, this would help.
Give a like if you are satified.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.