can i get a hint to this question?
Can i get a hint to this question?
This a question based on recursion. Try extracting substrings which when converted into integers are less than or equal to 26 in magnitude.
In the example given, 123, either you can convert 1 to A and ask recursion to bring the rest of the string for the leftover string 23. Or you can extract 12 and ask recursion to bring the rest of the string for the leftover string 23.
However, it is not possible to extract 123 as it is greater than 26.
Try implementing it using the above logic. If you face an issue, feel free to revert.
i am doing it and calling recursion to do for next but it is not working how can i do it for 12
Please send your code for reference
@anubhavb11
Thats now how you are supposed to do this.
This is my solution for the question. You will be able to attain a better understanding. Just go through it once and revert back in case you face any difficulties
thanks but how can i code like you do why cant i do it myself ?
and your code is too complex i am not able to understand it
@anubhavb11
Let me explain my code. I have tried to extract one and two characters from the string. If I take the first character, I append the corresponding alphabet to osf which stores the output so far in the recursion call.
I can also take two characters at once. But to able to that, there must be two characters left in the string.
That is the reason I have introduced the check for whether I am standing at the last index of the string or not. Now I take the first two characters of the string, convert it into an integer and check if it is less than or equal to 26. This is done because the integer cannot be greater than 26. After I append the corresponding alphabet to my osf string, I let recursion do the rest of the job. This is the approach behind the question.
Please revert if you face any issues in the logic.