Given two alphabet strings str1 and str2. You can change the characters in str1 to any alphabet characters in order to transform str1 to str2. One restriction is, in each operation, you should change all the same characters simultaneously.
What's more, you may use another special character * if necessary, which means during each operations, you may change the alphabet characters to *, or change each * to a specific character.
We want to know the minimum operation times. If impossible, return -1.
Template
int MinOpTimes(string str1, string str2) {
//...
};
Examples
Example 1:
str1: accs, str2: eeec
operation 1: change 'a'->'e'; // str1: eccs
operation 2: change 'c'->'e'; // str1: eees
operation 3: change 's'->'c'; // str1: eeec
return 3;
Example 2:
str1: accs, str2: efec
return -1;
Example 3:
str1: abb , str2: baa
operation 1: change 'a'->'*'; // str1: *bb
operation 2: change 'b'->'a'; // str1: *aa
operation 3: change '*'->'b'; // str1: baa
return 3;