XOR of every element of an Array with a given number K | Function to construct new array ; Traverse the array and compute XOR with K ; Print new array ; Driver code
def constructXORArray ( A , n , K ) : NEW_LINE INDENT B = [ 0 ] * n ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT B [ i ] = A [ i ] ^ K ; NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT print ( B [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT print ( ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 2 , 4 , 1 , 3 , 5 ] ; NEW_LINE K = 5 ; NEW_LINE n = len ( A ) ; NEW_LINE constructXORArray ( A , n , K ) ; NEW_LINE B = [ 4 , 75 , 45 , 42 ] ; NEW_LINE K = 2 ; NEW_LINE n = len ( B ) ; NEW_LINE constructXORArray ( B , n , K ) ; NEW_LINE DEDENT