Minimum string moves

We have two strings A and B which are permutations of the same set of characters. We need to change these strings to obtain two identical strings by performing  the following operations:

  1.   swap two consecutive characters of a string
  2.   swap the first and the last characters of a string

The operation can be performed on either string.
Return the minimum number of moves that we need in order to obtain two equal strings?

 

Constraints:

  • 1 < length(A) = length(B) ≤ 2,000
  • All the input characters are between ‘a’ and ‘z’
  • The count of each distinct character in A is identical to the count of the same character in B.

 

Input Format:
The function “easyStrings” contains two string “A” and “B” as its arguments respectively.

 

Output Format:
Return an integer denoting the minimum number of moves.

 

Sample Input #00:
aab
baa
Sample Output #00:
1

Explanation #00:
For example, swapping the first and last character of string aab converts it to baa, so both strings are now equal.


Download Test Case

You may also like

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments