how to proceed with the problem?
Mapped Strings Ques
Hey @samardeep to solve this question you can use recursion, have elaborated an approach below, which is implementation of recursion.
Letβs understand the question first.
Consider two examples:
- Letβs Start with 1023;
[1,2,3] =ABC
[1,23]=AW
[10,2,3]=JBC
[10,23]=JW
2. Now, coming to the next example 1432
[1,4,3,2]=ADCB
[14,3,2]=NCB
Approach :
- 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.
We will have 2 arguments in recursion input string and output string (no need to take an array)β
Say input string is 123 then Initial we have
( β123β ,"" )
now we can take 1 char if its not 0 so we will take 1 convert to A & make recursive call (β23β,βAβ)
Also we can take 2 char only if atleast two char left in string & they are >=10 & <=26 so current 2 digit num is 12 so we take it and convert to corresponding char and make recursive call (β3β ,βLβ)
from (β23β,βAβ) we can go to (β3β,βABβ) & ("",βAWβ) in second case since input is empty we can print output string
and rest of the recursion call will follow
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.