|  | 
|  | 1 | +<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> | 
|  | 2 | + | 
|  | 3 | +<p>Specifically, for each index <code>i</code> in the range <code>[0, n - 1]</code>:</p> | 
|  | 4 | + | 
|  | 5 | +<ul> | 
|  | 6 | +	<li>If <code>i = n - 1</code>, then <code>derived[i] = original[i] ⊕ original[0]</code>.</li> | 
|  | 7 | +	<li>Otherwise, <code>derived[i] = original[i] ⊕ original[i + 1]</code>.</li> | 
|  | 8 | +</ul> | 
|  | 9 | + | 
|  | 10 | +<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> | 
|  | 11 | + | 
|  | 12 | +<p>Return <em><strong>true</strong> if such an array exists or <strong>false</strong> otherwise.</em></p> | 
|  | 13 | + | 
|  | 14 | +<ul> | 
|  | 15 | +	<li>A binary array is an array containing only <strong>0's</strong> and <strong>1's</strong></li> | 
|  | 16 | +</ul> | 
|  | 17 | + | 
|  | 18 | +<p> </p> | 
|  | 19 | +<p><strong class="example">Example 1:</strong></p> | 
|  | 20 | + | 
|  | 21 | +<pre> | 
|  | 22 | +<strong>Input:</strong> derived = [1,1,0] | 
|  | 23 | +<strong>Output:</strong> true | 
|  | 24 | +<strong>Explanation:</strong> A valid original array that gives derived is [0,1,0]. | 
|  | 25 | +derived[0] = original[0] ⊕ original[1] = 0 ⊕ 1 = 1  | 
|  | 26 | +derived[1] = original[1] ⊕ original[2] = 1 ⊕ 0 = 1 | 
|  | 27 | +derived[2] = original[2] ⊕ original[0] = 0 ⊕ 0 = 0 | 
|  | 28 | +</pre> | 
|  | 29 | + | 
|  | 30 | +<p><strong class="example">Example 2:</strong></p> | 
|  | 31 | + | 
|  | 32 | +<pre> | 
|  | 33 | +<strong>Input:</strong> derived = [1,1] | 
|  | 34 | +<strong>Output:</strong> true | 
|  | 35 | +<strong>Explanation:</strong> A valid original array that gives derived is [0,1]. | 
|  | 36 | +derived[0] = original[0] ⊕ original[1] = 1 | 
|  | 37 | +derived[1] = original[1] ⊕ original[0] = 1 | 
|  | 38 | +</pre> | 
|  | 39 | + | 
|  | 40 | +<p><strong class="example">Example 3:</strong></p> | 
|  | 41 | + | 
|  | 42 | +<pre> | 
|  | 43 | +<strong>Input:</strong> derived = [1,0] | 
|  | 44 | +<strong>Output:</strong> false | 
|  | 45 | +<strong>Explanation:</strong> There is no valid original array that gives derived. | 
|  | 46 | +</pre> | 
|  | 47 | + | 
|  | 48 | +<p> </p> | 
|  | 49 | +<p><strong>Constraints:</strong></p> | 
|  | 50 | + | 
|  | 51 | +<ul> | 
|  | 52 | +	<li><code>n == derived.length</code></li> | 
|  | 53 | +	<li><code>1 <= n <= 10<sup>5</sup></code></li> | 
|  | 54 | +	<li>The values in <code>derived</code> are either <strong>0's</strong> or <strong>1's</strong></li> | 
|  | 55 | +</ul> | 
0 commit comments