no need to addi all element if overflow is feared , subtract values for given index in the loop something like this result = 0 ; for(count = 0; count < n ;count ++){ result += (B[count]-A[count]); } result += B[count] ; //! this is the answer...
-Manish On Sep 21, 9:44 am, Baljeet Kumar <baljeetk...@gmail.com> wrote: > 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 <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 > > -- > 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.