2433. Find The Original Array of Prefix Xor
IntuitionThe problem involves reconstructing an original array from a given prefix XOR array. The prefix XOR array is defined such that each element at index i
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem involves reconstructing an original array from a given prefix XOR array. The prefix XOR array is defined such that each element at index i in the prefix array is the XOR of all elements from the original array up to index i. The goal is to derive the original array from this prefix XOR array.


# Approach
<!-- Describe your approach to solving the problem. -->
1. **Understanding Prefix XOR:** The prefix XOR array is defined as:

    - pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]
    - To find the original array, we can use the property of XOR:
        - If a = b ^ c, then b = a ^ c and c = a ^ b.
    - From the prefix XOR, we can derive:
        - arr[i] = pref[i] ^ pref[i - 1] for i > 0
        - For the first element, arr[0] = pref[0] since there is no previous element to XOR with.
1. **Iterate Backwards:** We can iterate through the prefix array from the end to the beginning, updating the prefix array in place to derive the original array:
    - Start from the last element and move towards the first element, applying the XOR operation to reconstruct the original values.
1. **Return the Result:** After processing, the modified pref array will contain the original values.

# Complexity
- Time complexity: **O(n).**
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: **O(1).**
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    vector<int> findArray(vector<int>& pref) {
        int n = pref.size();
        for(int i = n - 1; i > 0; i--) {
            pref[i] ^= pref[i - 1];
        }
        return pref;
    }
};
```
['C++']