✅ Easiest Possible Approach ✅ Bit Manipulation ✅ Fastest Too
\n\n\n# YouTube Video Explanation:\n\nhttps://youtu.be/eNT1d-tB68k\n\n\uD83D\uDD25 Please like, share, and subscribe to support our channel\'s mission of making
![Screenshot 2023-10-31 075330.png](https://assets.leetcode.com/users/images/646b391e-5c6c-4059-9fa0-b4571015c4c7_1698719034.7725377.png)\n\n\n# YouTube Video Explanation:\n\n[https://youtu.be/eNT1d-tB68k](https://youtu.be/eNT1d-tB68k)\n\n**\uD83D\uDD25 Please like, share, and subscribe to support our channel\'s mission of making complex concepts easy to understand.**\n\nSubscribe Link: https://www.youtube.com/@leetlogics/?sub_confirmation=1\n\n*Subscribe Goal: 200 Subscribers*\n*Current Subscribers: 165*\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem essentially asks us to find the missing element in the `arr` array given the `pref` array. The `^` operator denotes the bitwise-xor operation. To find the missing element, we can apply the xor operation to the prefix array elements. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Create an integer array `result` of the same size as `pref`.\n2. Initialize the first element of `result` as `pref[0]` because `arr[0] = pref[0]`.\n3. Iterate through the `pref` array from index 1 to the end.\n4. For each element at index `i`, calculate `result[i]` as the xor of `pref[i]` and `result[i-1]` (the previously calculated element in the `result` array).\n5. Return the `result` array, which represents the `arr` array.\n\n# Complexity\n- Time Complexity: `O(n)` - We iterate through the `pref` array once, and each operation is constant time.\n- Space Complexity: `O(n)` - We use additional space to store the `result` array.\n\n# Code\n### Java\n```\nclass Solution {\n    public int[] findArray(int[] pref) {\n        int[] result = new int[pref.length];\n        result[0] = pref[0];\n\n        for(int i=1;i<pref.length;i++)\n        {\n            result[i] = pref[i] ^ pref[i-1];\n        }\n\n        return result;\n    }\n}\n```\n\n### C++\n```\nclass Solution {\npublic:\n    vector<int> findArray(vector<int>& pref) {\n        int n = pref.size();\n        vector<int> result(n);\n        result[0] = pref[0];\n\n        for (int i = 1; i < n; i++) {\n            result[i] = pref[i] ^ pref[i - 1];\n        }\n\n        return result;\n    }\n};\n```\n\n### Python\n```\nclass Solution(object):\n    def findArray(self, pref):\n        n = len(pref)\n        result = [0] * n\n        result[0] = pref[0]\n\n        for i in range(1, n):\n            result[i] = pref[i] ^ pref[i - 1]\n\n        return result\n        \n```\n\n### Javascript\n```\nvar findArray = function(pref) {\n    const n = pref.length;\n    const result = new Array(n);\n    result[0] = pref[0];\n\n    for (let i = 1; i < n; i++) {\n        result[i] = pref[i] ^ pref[i - 1];\n    }\n\n    return result;\n};\n```\n---\n\n![upvote1.jpeg](https://assets.leetcode.com/users/images/d2bb7dce-45ae-4223-bcb6-2cd51c9dbca1_1698718962.272012.jpeg)\n
['Array', 'Bit Manipulation', 'Python', 'C++', 'Java', 'JavaScript']