<p>You are given an <strong>integer</strong> array <code>pref</code> of size <code>n</code>. Find and return <em>the array </em><code>arr</code><em> of size </em><code>n</code><em> that satisfies</em>:</p>

<ul>
	<li><code>pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]</code>.</li>
</ul>

<p>Note that <code>^</code> denotes the <strong>bitwise-xor</strong> operation.</p>

<p>It can be proven that the answer is <strong>unique</strong>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> pref = [5,2,0,3,1]
<strong>Output:</strong> [5,7,2,3,2]
<strong>Explanation:</strong> From the array [5,7,2,3,2] we have the following:
- pref[0] = 5.
- pref[1] = 5 ^ 7 = 2.
- pref[2] = 5 ^ 7 ^ 2 = 0.
- pref[3] = 5 ^ 7 ^ 2 ^ 3 = 3.
- pref[4] = 5 ^ 7 ^ 2 ^ 3 ^ 2 = 1.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> pref = [13]
<strong>Output:</strong> [13]
<strong>Explanation:</strong> We have pref[0] = arr[0] = 13.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= pref.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= pref[i] &lt;= 10<sup>6</sup></code></li>
</ul>

class Solution:
    def findArray(self, pref):
        #a^b=c
        #given a and c can we find b?
        def reverse_xor(a,c):
            a=str(convert_to_base2(a))
            c=str(convert_to_base2(c))
            if len(a)>len(c):
                c="0"*(len(a)-len(c))+c
            else:
                a="0"*(len(c)-len(a))+a
            a=list(a)
            for i in range(len(a)):
                a[i]= "1" if ((a[i]=="0" and c[i]=="1" ) or (a[i]=="1" and c[i]=="0")) else "0"

            return convert_to_base10(int(''.join(a)))

        def convert_to_base2(num:int):
                # keep dividing a number by 2, and store its remeinder
                num=int(num)
                output=[]
                while num:
                    output.append(str(num%2))
                    num=num//2
                try:
                    return int(''.join(output[::-1]))          
                except: 
                    return 0
        def convert_to_base10(num:int):
            output=0
            i=0
            while num:
                output+=(num%10)*(2**i)
                num=num//10
                i+=1
            return output

        def main():
            output=[pref[0]]
            prev=pref[0]
            for ele in pref[1:]:
                output.append(reverse_xor(prev,ele))
                prev=ele

            return output
    
        return main()
35600