I have been trying to solve a question on permutation and haven't really been successful. I want to generate all the permutations of a specified length that start with a letter and end with the same,and no two consecutive letters should be the same. The permutations generated can have repeated letters.
For example,
if the array has {a,b,c,d} and i want all the permutations that start and end with a.
The answer should be:
abca
abda
acba
acda
adba
adca
If the array is {a,b,c,d,e}
Output:
abcda
abada
abdca
abaca
acbda
acada
acdba
acaba
adbca
adaca
adcba
adaba
abcba
ababa
abdba
acbca
acaca
acdca
adbda
adcda
adada
I would like to know if there is some way by which i can directly get to know the no.of solutions I will get for an array by some formula..
Thank You everyone in advance..