Find The Original Array of Prefix Xor

You are given an integer array pref of size n. Find and return the array arr of size n that satisfies:

  • pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]

Note that ^ denotes the bitwise-xor operation.

It can be proven that the answer is unique.

Example 1
Inputpref = [5,2,0,3,1]
Output[5,7,2,3,2]
From the array [5, 7, 2, 3, 2], the prefix xor values are 5, 2, 0, 3, and 1 respectively.
Example 2
Inputpref = [13]
Output[13]
We have pref[0] = arr[0] = 13.

Constraints

  • 1 <= pref.length <= 10^5
  • 0 <= pref[i] <= 10^6

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate