Did not find eror
@deepgarg46 You have assumed that only two-digit input will be given which is wrong. Instead use this logic. Talking about error in your if statement mapping should be written like this :
String ch=mapping[num-‘0’];
not like this :
String ch=mapping[num];
Overall your logic is wrong so you this Approach :
To Solve any Problem related to Recursion All you need to do is Break the Problem into 3 important components which are as follows :-
- Bigger Problem : The original Problem statement is your bigger problem.
- 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.
- 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.
Approach Discussion
- Bigger Problem : To Print all of the possible mapped String of given number.
- Smaller Problem : Assume the recursion works and will give you ans for just after the first digit.
- Self Work : In order to make you smaller prblm your problem all you need to work for the 0th index element. Because it could be the part included in the answer or not. So first number could be mapped as it is or can be mapped by including just the next digit with. For e.g…, 123 either first digit will be mapped as ‘1’ or as ‘12’ but not for ‘123’
Note : Do handle that the number should be smaller than 26 as for two digit number could be like 321 so your recursion will take either 3 or 32 but 32 is not valid.
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.