Find The Original Array of Prefix Xor

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
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.
LeetCode Problem - 1470
class Solution {
public int[] findArray(int[] pref) {
// Initialize a new array 'arr' with the same length as the 'pref' array.
int[] arr = new int[pref.length];
// Set the first element of the 'arr' array to be the same as the first element of the 'pref' array.
arr[0] = pref[0];
// Iterate through each index 'i' starting from 1 up to the length of the 'pref' array.
for (int i=1; i<pref.length; i++){
// Calculate the value of the current element in 'arr' by performing XOR operation
// between the current element in 'pref' and the previous element in 'pref'.
arr[i] = pref[i]^pref[i-1];
}
// Return the newly calculated array 'arr'.
return arr;
}
}




