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[i]; result is the number we need. On Tue, Sep 21, 2010 at 9:48 AM, vishal raja <vishal.ge...@gmail.com> 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 <anandut2...@gmail.com> 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 algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> 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 algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.