-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13e0ff9
commit 6316b40
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<h2><a href="https://leetcode.com/problems/neighboring-bitwise-xor/">2683. Neighboring Bitwise XOR</a></h2><h3>Medium</h3><hr><p>A <strong>0-indexed</strong> array <code>derived</code> with length <code>n</code> is derived by computing the <strong>bitwise XOR</strong> (⊕) of adjacent values in a <strong>binary array</strong> <code>original</code> of length <code>n</code>.</p> | ||
|
||
<p>Specifically, for each index <code>i</code> in the range <code>[0, n - 1]</code>:</p> | ||
|
||
<ul> | ||
<li>If <code>i = n - 1</code>, then <code>derived[i] = original[i] ⊕ original[0]</code>.</li> | ||
<li>Otherwise, <code>derived[i] = original[i] ⊕ original[i + 1]</code>.</li> | ||
</ul> | ||
|
||
<p>Given an array <code>derived</code>, your task is to determine whether there exists a <strong>valid binary array</strong> <code>original</code> that could have formed <code>derived</code>.</p> | ||
|
||
<p>Return <em><strong>true</strong> if such an array exists or <strong>false</strong> otherwise.</em></p> | ||
|
||
<ul> | ||
<li>A binary array is an array containing only <strong>0's</strong> and <strong>1's</strong></li> | ||
</ul> | ||
|
||
<p> </p> | ||
<p><strong class="example">Example 1:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> derived = [1,1,0] | ||
<strong>Output:</strong> true | ||
<strong>Explanation:</strong> A valid original array that gives derived is [0,1,0]. | ||
derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1 | ||
derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1 | ||
derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0 | ||
</pre> | ||
|
||
<p><strong class="example">Example 2:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> derived = [1,1] | ||
<strong>Output:</strong> true | ||
<strong>Explanation:</strong> A valid original array that gives derived is [0,1]. | ||
derived[0] = original[0] ⊕ original[1] = 1 | ||
derived[1] = original[1] ⊕ original[0] = 1 | ||
</pre> | ||
|
||
<p><strong class="example">Example 3:</strong></p> | ||
|
||
<pre> | ||
<strong>Input:</strong> derived = [1,0] | ||
<strong>Output:</strong> false | ||
<strong>Explanation:</strong> There is no valid original array that gives derived. | ||
</pre> | ||
|
||
<p> </p> | ||
<p><strong>Constraints:</strong></p> | ||
|
||
<ul> | ||
<li><code>n == derived.length</code></li> | ||
<li><code>1 <= n <= 10<sup>5</sup></code></li> | ||
<li>The values in <code>derived</code> are either <strong>0's</strong> or <strong>1's</strong></li> | ||
</ul> |