I was looking through a programming question, when the following question suddenly seemed related.
How do you convert a string to another string using as few swaps a
Hash Map data structure (that allows duplicates) is suitable for solving the problem.
Let the string be s1 and s2. The algorithm iterates through both the string and whenever a mismatch is found the algorithm maps the character of s1 to s2 i.e char of s1 as key and char of s2 as value is inserted in Hash Map wherever mismatch is occurred.
After this initialize the result as zero.
The next step is while the Hash Map is not empty do following:
result holds your desired output.