All N Length Strings from Given String of Length K
Objective: Print All N Length Strings from Given String of Length K where characters can appear multiple time.
String k = "ALGO" N=2 Result: AA LA GA OA AL LL GL OL AG LG GG OG AO LO GO OO
This problem is quite similar to Print All N Length Strings from Given Number K.
- Loop through i = 1 to K.
- Add k[i] to the result Array, which is the size N and make a recursive call to (N-1).
- Base case: when n becomes 0 (means array is full).
- See the code for better explanation.
Output: AA LA GA OA AL LL GL OL AG LG GG OG AO LO GO OO
Top Companies Interview Questions..-
If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.