ILD18MSM - 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:
- swap two consecutive characters of a string
- 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
First line: String A.
Second line: String B.
Output
Minimum number of moves.
Example
Input: aab baa Output: 1
hide comments
khoaph:
2021-03-14 13:52:46
@Jaffar,that is not moving aa. That is swapping the first character and the last character. |
|
Sayed Jaffar:
2021-01-29 11:45:10
does operation 1 meaning : aab -> aba (swap a with b) || aab -> baa (move aa one position) ? |
Added by: | Gầy :)) |
Date: | 2019-11-11 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | hackerrank |