You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on sany number of times:
Choose two different indices i and j where 0 <= i, j < n.
Simultaneously, replace s[i] with (s[i]ORs[j]) and s[j] with (s[i]XORs[j]).
For example, if s = "0110", you can choose i = 0 and j = 2, then simultaneously replace s[0] with (s[0]ORs[2] = 0OR1 = 1), and s[2] with (s[0]XORs[2] = 0XOR1 = 1), so we will have s = "1110".
Return trueif you can make the stringsequal totarget, orfalseotherwise.
Input: s ="1010", target ="0110"Output: trueExplanation: We can do the following operations:- Choose i =2 and j =0. We have now s ="**_0_** 0** _1_** 0".- Choose i =2 and j =1. We have now s ="0** _11_** 0".Since we can make s equal to target, we returntrue.
The key insight is that the allowed operation lets us freely move and combine 1s in the string, but we can never create a 1 if there wasn’t one to begin with. Thus, if both s and target have at least one 1, we can always transform s into target. If both are all 0s, they’re already equal. If one has 1 and the other doesn’t, it’s impossible.