There can be overflow in case of adding up all the elements. Use Xor
instead.

>
> int result = 0;
> for (int i = 0; i < n ;i++){
>       result ^= A[i]^B[i];
> }
>
> result ^= B[n]; <=== (correction)
> result is the number we need.
>
> On Tue, Sep 21, 2010 at 9:48 AM, vishal raja <[email protected]>wrote:
>
>> add up all the elements in array A  say sumA and array B say sumB
>> ,substract the sumA from sumB... You'll get the element.
>>
>>
>> On Tue, Sep 21, 2010 at 5:36 AM, Anand <[email protected]> wrote:
>>
>>> Two unsorted arrays are given A[n] and B[n+1]. Array A contains n
>>> integers and B contains n+1 integers of which n are same as in array B but
>>> in different order and one extra element x. Write an optimized algorithm to
>>> find the value of element x. Use only one pass of both arrays A and B.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected]<algogeeks%[email protected]>
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> Baljeet Kumar
>
>
>


-- 
Baljeet Kumar

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to