1371. Find the Original Array of Prefix XOR

MediumBit ManipulationXORPrefixBit Manipulation

You are given an array pref where pref[i] equals the XOR of arr[0] through arr[i] for some hidden array arr. Reconstruct and return arr, which is guaranteed to be unique.

Input: A JSON object {"pref": [<non-negative integers>]}.

Output: Return the original array arr.

Examples

Example 1
Input: {"pref":[5,2,0,3]}
Output: [5,7,2,3]
Explanation: Successive prefix XORs recover [5,7,2,3].
Example 2
Input: {"pref":[13]}
Output: [13]
Explanation: With one prefix the array is itself -> [13].

Constraints

Asked by

Microsoft
Solve this problem in the editor →