int main() {

int a[] = {1,2,2,3,3,3,4,4};

int size = sizeof(a)/sizeof(a[0]);
int xorr=0;
for(int i=0;i<size;i++) {
xorr^=a[i];
}

int x=0,y=0;

int xor1=xorr & ~(xorr-1);

for(int i=0;i<size;i++) {
 if(xor1 & a[i]) x^=a[i];
 else y^=a[i];
}

cout<< x <<" " << y;

}

in this 1 and 3 would be output. as it would be print the number repeated
odd times. so ur answer would be in y ie 3 .

If there issue with the code let me knw.


On Fri, Apr 19, 2013 at 10:52 AM, Krishnan <aariyankrish...@gmail.com>wrote:

> In an array, some numbers occur only once, some numbers occur twice, only
> one number occur thrice. Find the number occuring thrice ? Space complexity
> O(1) Time Complexity O(n). We should not use Hash Maps.
>
> Please someone help..
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to