Revealing the Original Array: A Cumulative XOR Approach 🚀
Intuition\n Describe your first thoughts on how to solve this problem. \nWhen I first looked at this problem, my initial thought was to make use of the property
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhen I first looked at this problem, my initial thought was to make use of the property of XOR: if ```a ^ b = c```, then ```a ^ c = b```. This property can be used to decipher the original array from the prefix XOR array.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nMy approach was to iterate through the prefix array and calculate the original array values cumulatively. I started by taking the first element as it is because ```pref[0]``` is equal to ```arr[0]```. For subsequent values, I applied the XOR operation between the previous original number and the current prefix value. This helped in uncovering the original numbers one by one and thus building the original array cumulatively.\n\n# Complexity\n- Time complexity: $$O(n)$$ (As we are iterating through the prefix array once)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$ (Since we are utilizing the input array to store the results and not using any extra space)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n#include <bits/stdc++.h>\nusing namespace std;\n#define ll long long\n#define db double\n#define pb push_back\n#define pi acos(-1.0)\n#define mod 1000000007\n\nclass Solution\n{\npublic:\n    vector<int> findArray(vector<int> &pref)\n    {\n        int prevNum = pref[0];\n        int n = pref.size();\n        for (int i = 1; i < n; i++)\n        {\n            int temp = prevNum ^ pref[i];\n            prevNum = pref[i];\n            pref[i] = temp;\n        }\n        return pref;\n    }\n};\n```
['Array', 'Bit Manipulation', 'C++']