Mapped Strings Ques

how to proceed with the problem?

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:

  1. 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.