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