Apply Bitwise Operations to Make Strings Equal

You are given two 0-indexed binary strings s and target of the same length n. You can do the following operation on s any number of times:

  • Choose two different indices i and j where 0 <= i, j < n.
  • Simultaneously, replace s[i] with (s[i] OR s[j]) and s[j] with (s[i] XOR s[j]).

Return true if you can make the string s equal to target, or false otherwise.

Example 1
Inputs = "1010", target = "0110"
Outputtrue
The operations can transform s from "1010" into "0110", so s can be made equal to target.
Example 2
Inputs = "11", target = "00"
Outputfalse
It is not possible to make s equal to target with any number of operations.

Constraints

  • n == s.length == target.length
  • 2 <= n <= 10^5
  • s and target consist of only the digits 0 and 1.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate