Find elements of array using XOR of consecutive elements | Function to find the array elements using XOR of consecutive elements ; array to store the original elements ; first elements a i . e elements [ 0 ] = a ; To get the next elements we have to calculate xor of previous elements with given xor of 2 consecutive elements . e . g . if a ^ b = k1 so to get b xor a both side . b = k1 ^ a ; Printing the original array elements ; Driver code
def getElements ( a , arr , n ) : NEW_LINE INDENT elements = [ 1 for i in range ( n + 1 ) ] NEW_LINE elements [ 0 ] = a NEW_LINE for i in range ( n ) : NEW_LINE INDENT elements [ i + 1 ] = arr [ i ] ^ elements [ i ] NEW_LINE DEDENT for i in range ( n + 1 ) : NEW_LINE INDENT print ( elements [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 13 , 2 , 6 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE a = 5 NEW_LINE getElements ( a , arr , n ) NEW_LINE