#2433
Find The Original Array of Prefix Xor
pupil · 375 · lc medium +23 · verified · 88.3% accepted · 1,508 likes · top 99%
Description
You are given an integer array pref of size n. Find the unique array arr of size n satisfying pref[i] = arr[0] XOR arr[1] XOR ... XOR arr[i] for all i.
Return arr.
Example 1:
Input: pref = [5,2,0,3,1]
Output: [5,7,2,3,2]
Explanation: From the array [5,7,2,3,2] we have the following:
- pref[0] = 5.
- pref[1] = 5 ^ 7 = 2.
- pref[2] = 5 ^ 7 ^ 2 = 0.
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
Example 2:
Input: pref = [13]
Output: [13]
Explanation: We have pref[0] = arr[0] = 13.
Code
1
2
3