java.lang.Object
g2601_2700.s2683_neighboring_bitwise_xor.Solution

public class Solution extends Object
2683 - Neighboring Bitwise XOR.<p>Medium</p> <p>A <strong>0-indexed</strong> array <code>derived</code> with length <code>n</code> is derived by computing the <strong>bitwise XOR</strong> (\u2295) 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] \u2295 original[0]</code>.</li> <li>Otherwise, <code>derived[i] = original[i] \u2295 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&rsquo;s</strong> and <strong>1&rsquo;s</strong></li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> derived = [1,1,0]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> A valid original array that gives derived is [0,1,0].</p> <p>derived[0] = original[0] \u2295 original[1] = 0 \u2295 1 = 1</p> <p>derived[1] = original[1] \u2295 original[2] = 1 \u2295 0 = 1</p> <p>derived[2] = original[2] \u2295 original[0] = 0 \u2295 0 = 0</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> derived = [1,1]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> A valid original array that gives derived is [0,1].</p> <p>derived[0] = original[0] \u2295 original[1] = 1</p> <p>derived[1] = original[1] \u2295 original[0] = 1</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> derived = [1,0]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> There is no valid original array that gives derived.</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&rsquo;s</strong> or <strong>1&rsquo;s</strong></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • doesValidArrayExist

      public boolean doesValidArrayExist(int[] derived)