Description
Solutions
Minimum Steps Required
📚RELATED PROBLEMS
Given two strings str1
and str2
containing only 0s and 1s, there are steps to change str1
to str2
:
str1
of length 2 and reverse it, resulting in str1'
(where str1'
!= str1
).str1'
of length 3, reverse it, resulting in str1''
(where str1''
!= str1'
).String length ranges from 2 to 30.
Requirements: 🤩
str1
to str2
, output the minimum required steps. Otherwise, output -1.Example 1:
Input: str1 = "1010", str2 = "0011"
Output: 2
Explanation:Steps:Choose substring in range [2, 3]: "1010" → "1001" Choose substring in the range [0, 2]: "1001" → "0011"
Example 2:
Input: str1 = "1001", str2 = "0110"
Output: -1
Explanation:It's impossible to changestr1
tostr2
.
Example 3:
Input: str1 = "10101010", str2 = "00101011"
Output: 7
Explanation:The minimum steps required to changestr1
tostr2
is 7.
Constraints:
N/A

Related Problems
Testcase
Result
Case 1
input:
output: