Hello,
I am having trouble thinking about the logic if someone could give any hint. Please do not write code for it.
The problem is like, I am given a string say MONK and an integer say 7. So what I want is to get all possible combination of 7 letter words out of MONK so that the order is not disturbed. Since MONK is 4 letter words and I want all the 7 letter words, the extra 3 letters could be anything say underscore _ .
So the answer for the question above should be
M O N K _ _ _
M _ O _ N K _
M O N _ _ _ K
M _ _ _ O N K
Hmm if I understand you properly, I guess you could have a dictionary text file and then search all strings containing the substring "monk" ?? ... Obviously checking the length of each word also.
You know that the 'M' must occur in positions 1, 2, 3, or 4 (otherwise there aren't enough letters left for the O, N, and K).
When the M is in the 1st position, for example, then you know that the O must occur in positions 2, 3, 4, or 5 (for a similar reason regarding the N and K).
When the M is in the 1st position AND the O is in the 2nd position, then you know that the N must occur in positions 3, 4, 5, or 6.
I'll post again if/when I come up with something that actually works XD
EDIT yet again:
UGH
okay so I think I got it.
Starting with a smaller example, 2 letters in 5 slots. You start with all letters on the right side:
---XX
- Find the right-most X that has an empty spot to its left, and move it left
- then reset all Xs to the right of it to their starting position
1 2 3 4 5 6 7 8 9
--a-b -> move b
--ab- -> move a, reset b
-a--b -> move b
-a-b- -> move b
-ab-- -> move a, reset b
a---b -> move b
a--b-
a-b--
ab---
Another example, 3/5:
1 2 3 4 5 6 7 8 9 10
--abc -> move a, reset bc
-a-bc -> move b, reset c
-ab-c -> move c
-abc- -> move a, reset bc
a--bc -> move b, reset c
a-b-c -> move c
a-bc- -> move b, reset c
ab--c
ab-c-
abc--