Description
Solutions
Transform String (Google India)
πŸ”₯ FULLTIME

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.

Example 1:

Input:  str1 = "zxyz", str2 = "zyxz"
Output: 6
Explanation:
zxyz -> yyxz -> yyzz -> yzxz -> zxxz -> zyxz -> zyxz

Example 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.

Example 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.

Example 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.

Example 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:
    πŸ‰πŸ‰
Thumbnail 0
Testcase

Result
Case 1

input:

output: