Find the Original Array of Prefix XOR

Given an array pref where pref[i] is the XOR of the first i + 1 elements of the original array, return the original array. Pattern focus: XOR State Tracking. The current prefix state can be undone by XORing consecutive prefix values.

Input Format

pref = prefix XOR array

Output Format

the original array

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • pref must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

pref = [5,2,0,3,1]

Output:

[5,7,2,3,2]

Explanation:

Each original value is pref[i] XOR pref[i-1].

Example 2:

Input:

pref = [13]

Output:

[13]

Explanation:

A single prefix XOR value means the original array has one element.

Loading...
Find the Original Array of Prefix XOR