Find the two non | This function sets the values of * x and * y to non - repeating elements in an array arr [ ] of size n ; Xor all the elements of the array all the elements occuring twice will cancel out each other remaining two unnique numbers will be xored ; Bitwise & the sum with it ' s ▁ 2' s Complement Bitwise & will give us the sum containing only the rightmost set bit ; sum1 and sum2 will contains 2 unique elements elements initialized with 0 box number xored with 0 is number itself ; Traversing the array again ; Bitwise & the arr [ i ] with the sum Two possibilities either result == 0 or result > 0 ; If result > 0 then arr [ i ] xored with the sum1 ; If result == 0 then arr [ i ] xored with sum2 ; Print the the two unique numbers ; Driver Code
def UniqueNumbers2 ( arr , n ) : NEW_LINE INDENT sums = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT sums = ( sums ^ arr [ i ] ) NEW_LINE DEDENT sums = ( sums & - sums ) NEW_LINE sum1 = 0 NEW_LINE sum2 = 0 NEW_LINE for i in range ( 0 , len ( arr ) ) : NEW_LINE INDENT if ( arr [ i ] & sums ) > 0 : NEW_LINE sum1 = ( sum1 ^ arr [ i ] ) NEW_LINE else : NEW_LINE sum2 = ( sum2 ^ arr [ i ] ) NEW_LINE DEDENT print ( " The ▁ non - repeating ▁ elements ▁ are ▁ " , sum1 , " ▁ and ▁ " , sum2 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 3 , 7 , 9 , 11 , 2 , 3 , 11 ] NEW_LINE n = len ( arr ) NEW_LINE UniqueNumbers2 ( arr , n ) NEW_LINE DEDENT