LeetCodeMetaData / apply-bitwise-operations-to-make-strings-equal.json
DataRepo's picture
Upload part 1 of 2
4097b71 verified
{
"id": 2632,
"name": "apply-bitwise-operations-to-make-strings-equal",
"difficulty": "Medium",
"link": "https://leetcode.com/problems/apply-bitwise-operations-to-make-strings-equal/",
"date": "2023-01-15",
"task_description": "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]`). For example, if `s = \"0110\"`, you can choose `i = 0` and `j = 2`, then simultaneously replace `s[0]` with (`s[0]` **OR** `s[2]` = `0` **OR** `1` = `1`), and `s[2]` with (`s[0]` **XOR** `s[2]` = `0` **XOR** `1` = `1`), so we will have `s = \"1110\"`. Return `true` _if you can make the string _`s`_ equal to _`target`_, or _`false`_ otherwise_. **Example 1:** ``` **Input:** s = \"1010\", target = \"0110\" **Output:** true **Explanation:** 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 return true. ``` **Example 2:** ``` **Input:** s = \"11\", target = \"00\" **Output:** false **Explanation:** It is not possible to make s equal to target with any number of operations. ``` **Constraints:** `n == s.length == target.length` `2 <= n <= 105` `s` and `target` consist of only the digits `0` and `1`.",
"test_case": [
{
"label": "Example 1",
"input": "s = \"1010\", target = \"0110\"",
"output": "true "
},
{
"label": "Example 2",
"input": "s = \"11\", target = \"00\"",
"output": "false "
}
],
"constraints": [
"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]).",
"n == s.length == target.length",
"2 <= n <= 105",
"s and target consist of only the digits 0 and 1."
],
"python_template": "class Solution(object):\n def makeStringsEqual(self, s, target):\n \"\"\"\n :type s: str\n :type target: str\n :rtype: bool\n \"\"\"\n ",
"java_template": "class Solution {\n public boolean makeStringsEqual(String s, String target) {\n \n }\n}",
"metadata": {
"func_name": "makeStringsEqual"
}
}