Sir i tried the problem but unable make it

Sir i tried the problem but unable make it ,Could you please share me the code so that i could know how to do it…for a better understanding

To Solve any Problem related to Recursion All you need to do is Break the Problem into 3 important components which are as follows :-

  1. Bigger Problem : The original Problem statement is your bigger problem.
  2. Smaller Problem : In every recursive prblm there exist a prblm statement which you need to achieve in order to fullfill the prblm statement but by considering such a smaller prblm from the bigger prblm is needed which we need to assume that the recursion will work and will give the answer.
  3. Self Work : The amount of work which one should do in order to make the smaller problem your problem.

For e.g…, In order to find the max of any array, three components will be :-
Bigger Problem : To find the max in whole array viz find max in array from index 0 to n - 1.
Smaller Problem : Assume that the recursion works and will find the max of array from index 1 to n - 1.
__Self Work : In order to make your smaller prblm your bigger prblm all you need to do is to compare the ans return by assuming the smaller prblm works with the 0th index element and return the max among both of them.

Similarly Classification acc to the Given prblm :-

  • Bigger Problem : To Print the codes for given whole length String.
  • Smaller Problem : Assume the recursion works and will give you ans for String of length n - 1 .
    Self Work : In order to make you smaller prblm your problem all you need to work for the first character and add one by one your all possible codes in the ans and the work will be done.

Note : In order to keep track of both of the sum of included numbers and answer so far we need to take 2 variables :-

  • ssf : It is basically sum so far of all elements included in the answer.
  • ans : It is declared to keep track of numbers which are a part of the sum.
  • cnt : Local variable to return the total number of count.

here is the code:

mam , you explained it very well …I got what I was missing

glad :smiley: if this solves your doubt please mark it as resolved