I tried this code on eclipse IDE. it seems to give correct output but still one of the testcases is not passed.
All test cases not passing
@nik1898,
In case length of input string is greater than 6, your code is giving stack over flow error.
Example Input:
1234567
Try to further optimize it.
i don’t see away to modify it further. can you please do it
i don’t see a way to modify it further. can you please do it
its a stack overflow error
olus this same code is working with string with length more than 6 on eclipse IDE
@nik1898,
Sure, please refer to the code below.
Approach:
- 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.
Also, apologizes for the delay in response. Hope it helps.
yes sir, it did work. thanks a lot for helping me out. The way you explained the approach helped me understand the code better.
1 Like