A binary array original of length n produces derived by taking the bitwise XOR of each value with its next neighbor. The last value uses the first value as its next neighbor. Thus derived[i] = original[i] XOR original[(i + 1) % n].
Given derived, return true if any binary array original of the same length can produce it, and false otherwise. A binary array contains only 0 and 1.
Example 1:
Input: derived = [0,1,0,1]
Output: trueExplanation: An original array [0,0,1,1] produces the adjacent XOR values [0,1,0,1], including the last-to-first edge.
Example 2:
Input: derived = [1]
Output: falseExplanation: A one-element original array XORs its only value with itself, which always gives 0. Therefore derived = [1] is impossible.
Example 3:
Input: derived = [0]
Output: trueExplanation: The original array [0] produces derived = [0], so a valid original exists.
Constraints:
1 <= derived.length <= 100000- Each value in
derivedis0or1.