2896. Apply Operations to Make Two Strings Equal
You are given two 0-indexed binary strings
s1ands2, both of lengthn, and a positive integerx.You can perform any of the following operations on the string
s1any number of times:
- Choose two indices
iandj, and flip boths1[i]ands1[j]. The cost of this operation isx.- Choose an index
isuch thati < n - 1and flip boths1[i]ands1[i + 1]. The cost of this operation is1.Return the minimum cost needed to make the strings
s1ands2equal, or return-1if it is impossible.Note that flipping a character means changing it from
0to1or vice-versa.
1 | class Solution { |