How to find number of ways of permuting a string satisfying the below conditions? I am given a string,let say- "abcd".
Now I have to find all the strings that can be generated by permuting its character such that-

  
*
  
*There are exactly four mismatches in the generated strings and,
  
*The mismatches exists in pair, for e.g-
  

The string - "abcd" has three such permutations-
"badc","cdab","dcba".
Explanation-
Let us consider "abcd" and "badc". Now there are exactly four mismatch with , i.e- (a,b),(b,a),(c,d),(d,c) and these mismatches exists in pair.
Note that "abcde" has fifteen such permutations-
acbed,adebc,aedcb,baced,badce,baedc,cbaed,cdabe,ceadb,dbeac,dcbae,decab,ebdca,ecbda,edcba
Where I am failing?-
I am just finding the strings manually, but this becomes really time-consuming for strings of large length. Hence,I need a efficient solution
 A: Hint:  Let the string have length $n$.  You choose two places for the first pair to swap, $n \choose 2$ ways. Then you choose two places for the second pair in (how many?) ways. But you could have chosen the pairs in the other order....
A: Break it up via multiplication principle:
$$abcdefgh$$


*

*Step 1: Pick which four of the $n$ letters are going to be swapped  (for example $bdeg$, pictured below)


$$\color{grey}{a}\color{red}{b}\color{grey}{c}\color{red}{de}\color{grey}{f}\color{red}{g}\color{grey}{h}$$
How many ways can this step be done in for a string of $n$ letters?

 $\binom{n}{4} = \frac{n!}{4!(n-4)!}$



*

*Step 2: Color the smallest appearing chosen letter blue.  Pick one more of the three remaining red chosen letters to color blue.  (for example $g$ pictured below)


$$\color{grey}{a}\color{blue}{b}\color{grey}{c}\color{red}{de}\color{grey}{f}\color{blue}{g}\color{grey}{h}$$
How many ways can this step be done?

 $3$ ways

Now, swap the blue letters, and swap the red letters.
$$agcedfbh$$
The pictured example has the following two mismatch pairs: $(b,g)$ and $(d,e)$.
It should be clear that every sequence of choices from the above steps will generate exactly a permutation of the desired type uniquely and that all permutations are generated by exactly one sequence of choices.  Multiplication principle then says that the number of such permutations is the product of the number of available choices at each step.

Beginnings of a generalization:
Let the string to be permuted be $\underbrace{aa\dots a}_{\alpha_a~\text{copies}} \underbrace{bb\dots b}_{\alpha_b~\text{copies}} cc\dots c\dots \underbrace{kk\dots k}_{\alpha_k~\text{copies}}$ where there are $k$ distinct letters appearing, and $\alpha_a+\alpha_b+\dots+\alpha_k = n$ letters total (counting repeated letters).
Let $\chi_{a,0}$ denote the event that two $a$'s were swapped between themselves and no other $a$'s were swapped.  Let $\chi_{a,1}$ denote the event that two $a$'s were swapped between themselves and a third $a$ was swapped with a different letter.  Let $\chi_{a,2}$ denote the event that four $a$'s were swapped amongst eachother.  Define similar events for the other letters.
Temporarily assume every letter distinct (each copy of a particular letter, assume it has a specific subscript number for example)
$$a_1b_1b_2b_3b_4c_1c_2c_3d_1e_1f_1f_2$$
Count how many permutations exist with the desired properties as above temporarily ignoring the fact that some letters are intended to be identical.

 $3\binom{n}{4}$ ways

Remove those permutations which swap at least one pair of identical letters.  To count how many of these there are, we try to count $|\chi_{a,0}\cup \chi_{a,1}\cup \chi_{a,2}\cup \chi_{b,0}\cup \dots\cup \chi_{k,2}|$.
By inclusion exclusion, this is $\sum\limits_{x\in\{a,b,\dots,k\}}\sum\limits_{i=0}^2|\chi_{x,i}| -\sum\limits_{\{x,y\}\subset\{a,b,\dots,k\},~x< y}|\chi_{x,0}\cap \chi_{y,0}|$
To count $|\chi_{x,0}|$, pick the two offending letter $x$'s, and then pick the other two non-$x$'s.  $\binom{\alpha_x}{2}\binom{n-\alpha_x}{2}$ such permutations.
To count $|\chi_{x,1}|$, pick the three offending $x$'s, pick one of them to be paired with a non-$x$, and pick the non $x$ to be paired with.  $\binom{\alpha_x}{3}\cdot 3\cdot (n-\alpha_x)$ such permutations.
To count $|\chi_{x,2}|$, pick the four offending $x$'s and then pick how they were paired.  $3\binom{\alpha_x}{4}$ such permutations.
Notice, that in expanding the union for inclusion-exclusion, the only surviving intersections are of the form $\chi_{x,0}\cap \chi_{y,0}$ with $x\neq y$ since any other intersection would imply that there were five or more selected letters.
To count $|\chi_{x,0}\cap \chi_{y,0}|$, select the two offending $x$'s and select the two offending $y$'s.  $\binom{\alpha_x}{2}\binom{\alpha_y}{2}$ such permutations.
Removing these from the original total, we have then a final total of:
$$3\binom{n}{4} - \sum\limits_{x\in \{a,b,\dots,k\}}\left(\binom{\alpha_x}{2}\binom{n-\alpha_x}{2}+\binom{\alpha_x}{3}\cdot 3\cdot (n-\alpha_x)+3\binom{\alpha_x}{4}\right) + \sum\limits_{\{x,y\}\subset\{a,b,\dots,k\},~x<y}\binom{\alpha_x}{2}\binom{\alpha_y}{2}$$
For a specific example, such as $abbbbcccdeff$, we would have $3\binom{12}{4} - \underbrace{\binom{4}{2}\binom{8}{2}}_{\chi_{b,0}} - \underbrace{\binom{4}{3}3\cdot 8}_{\chi_{b,1}} - \underbrace{3}_{\chi_{b,2}} - \underbrace{\binom{3}{2}}_{\chi_{c,0}}-\underbrace{\binom{3}{3}\cdot 3\cdot 9}_{\chi_{c,1}}-\underbrace{\binom{2}{2}\binom{10}{2}}_{\chi_{f,0}}+\underbrace{\binom{4}{2}\binom{3}{2}}_{\chi_{b,0}\cap\chi_{c,0}}+\underbrace{\binom{4}{2}\binom{2}{2}}_{\chi_{b,0}\cap\chi_{f,0}}+\underbrace{\binom{3}{2}\binom{2}{2}}_{\chi_{c,0}\cap\chi_{f,0}} = 1170$
For a smaller example which should be able to be brute forced, $abbde$ would have $3\binom{5}{4} - \binom{2}{2}\binom{3}{2} = 15-3=12$.  Specifically, they are $adebb,aedbb,babed,badbe,baedb,bbaed,bdabe,beadb,dbeab,debab,ebdba,edbba$ (copied from your earlier list, replaced $c$'s with $b$'s, and deleted the three offending permutations)
