2683. Neighboring Bitwise XOR

Difficulty:
Related Topics:
Similar Questions:

    Problem

    A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.

    Specifically, for each index i in the range [0, n - 1]:

    Given an array derived, your task is to determine whether there exists a valid binary array original that could have formed derived.

    Return **true if such an array exists or false otherwise.**

    Example 1:

    Input: derived = [1,1,0]
    Output: true
    Explanation: A valid original array that gives derived is [0,1,0].
    derived[0] = original[0] ⊕ original[1] = 01 = 1
    derived[1] = original[1] ⊕ original[2] = 10 = 1
    derived[2] = original[2] ⊕ original[0] = 00 = 0
    

    Example 2:

    Input: derived = [1,1]
    Output: true
    Explanation: A valid original array that gives derived is [0,1].
    derived[0] = original[0] ⊕ original[1] = 1
    derived[1] = original[1] ⊕ original[0] = 1
    

    Example 3:

    Input: derived = [1,0]
    Output: false
    Explanation: There is no valid original array that gives derived.
    

    Constraints:

    Solution (Java)

    class Solution {
        public boolean doesValidArrayExist(int[] de) {
            int ans=0;
            for(int a:de){
                if(a==1)
                    ans++;
            }
            return (ans%2==0);
        }
    }
    

    Explain:

    nope.

    Complexity: