Problem Brief
Transform String (Google India)
FULLTIMEPHONE SCREEN
See Google online assessment and hiring insights
Given two strings of equal length made up of 'x', 'y', and 'z', with no consecutive characters the same, determine the minimum number of operations needed to transform the first string into the second. In one operation, you can change any character in the first string, ensuring no consecutive characters become identical.
1Example 1
Input
str1 = "zxyz", str2 = "zyxz"
Output
6
Explanation
zxyz -> yyxz -> yyzz -> yzxz -> zxxz -> zyxz -> zyxz
2Example 2
Input
str1 = "xzyzyzyzxyz", str2 = "xzyzyzyzyxy"
Output
15
Explanation
The minimum number of operations needed to transform the first string into the second is 15.
3Example 3
Input
str1 = "xyyxyxyxyy", str2 = "xzyxyzyxzx"
Output
13
Explanation
The minimum number of operations needed to transform the first string into the second is 13.
4Example 4
Input
str1 = "xyyxyzzyxy", str2 = "zyzyzyzyzyz"
Output
9
Explanation
The minimum number of operations needed to transform the first string into the second is 9.
5Example 5
Input
str1 = "xzxyxyzzyxyz", str2 = "zyzyzyzyzyzy"
Output
20
Explanation
The minimum number of operations needed to transform the first string into the second is 20.
Constraints
Limits and guarantees your solution can rely on.
๐๐