//Program To Find The Element Not In Pair { In 0(n) Complexity } // Returns 0 If All Elements Are Paired int findUnpairedElement(int arr[],int n){ int unpaired_element = 0; for(int i=0; i


Others
SUBRAMANI S
2 14 1634
6 months ago

//Program To Find The  Element Not In Pair { In 0(n) Complexity } // Returns 0 If All Elements Are Paired

int findUnpairedElement(int arr[],int n){    
    int unpaired_element = 0;                               
    for(int i=0; i<n; i++){                            //xor properties
        unpaired_element ^= arr[i];       // a ^ 0 = a 
    }                                                                       // a ^ a = 0                
    return(unpaired_element);            // so each time duplicate element is encountered its gets cancelled
}

/* Happy Leaning */  :-)

Jayashree kumaran
0 0 134
5 months ago

can u explain ths