Description
There is a hidden integer array arr. You are given the integer first and an array encoded where encoded[i] = arr[i] XOR arr[i + 1]. Return the original array arr.
Examples
Input:
encoded = [1,2,3], first = 1Output:
[1,0,2,1]Explanation:
XOR back.
Input:
encoded = [5,7], first = 3Output:
[3,6,1]Explanation:
Start with first=3. Since encoded[0]=arr[0] XOR arr[1], 5=3 XOR arr[1], so arr[1]=3 XOR 5=6. Then encoded[1]=arr[1] XOR arr[2], 7=6 XOR arr[2], giving arr[2]=6 XOR 7=1.
Input:
encoded = [0,8,4,2], first = 9Output:
[9,9,1,5,7]Explanation:
Starting with first=9: arr[1]=9 XOR 0=9, arr[2]=9 XOR 8=1, arr[3]=1 XOR 4=5, arr[4]=5 XOR 2=7. Notice that when encoded[i]=0, consecutive elements in the original array are identical.
Constraints
- •
2 ≤ n ≤ 10⁴