Find the element that appears once in an array where every other element appears twice |  ; singleelement function ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int singleelement ( int arr [ ] , int n ) { int low = 0 , high = n - 2 ; int mid ; while ( low <= high ) { mid = ( low + high ) / 2 ; if ( arr [ mid ] == arr [ mid ^ 1 ] ) { low = mid + 1 ; } else { high = mid - 1 ; } } return arr [ low ] ; } int main ( ) { int arr [ ] = { 2 , 3 , 5 , 4 , 5 , 3 , 4 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort ( arr , arr + size ) ; cout << singleelement ( arr , size ) ; return 0 ; }