Be the first user to complete this post
|
Add to List |
166. 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 times.
Example:
String k = ALGO N=2 Result: AA LA GA OA AL LL GL OL AG LG GG OG AO LO GO OO
Approach:
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