Count all pairs with given XOR | Returns count of pairs in arr [ 0. . n - 1 ] with XOR value equals to x . ; create empty set that stores the visiting element of array . ; If there exist an element in set s with XOR equals to x ^ arr [ i ] , that means there exist an element such that the XOR of element with arr [ i ] is equal to x , then increment count . ; Make element visited ; return total count of pairs with XOR equal to x ; Driver Code
def xorPairCount ( arr , n , x ) : NEW_LINE INDENT s = set ( ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( x ^ arr [ i ] in s ) : NEW_LINE INDENT result = result + 1 NEW_LINE DEDENT s . add ( arr [ i ] ) NEW_LINE DEDENT return result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 4 , 10 , 15 , 7 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE x = 5 NEW_LINE print ( " Count ▁ of ▁ pair ▁ with ▁ given ▁ XOR ▁ = ▁ " + str ( xorPairCount ( arr , n , x ) ) ) NEW_LINE DEDENT