Yes Doing XOR Is much better idea. Using SUM method we may face overflow problem which could be solved by strin implementation of a Number(extra memory) So its better to go with first solution.-
Atul On Thu, Feb 4, 2010 at 11:05 PM, Agraj Mangal <agraj....@gmail.com> wrote: > The XOR solution is better than the SUM method as SUM could result in > overflow and hence wrong answer, which would not happen with XOR solution. > > Please correct me if i m wrong. > > > On Mon, Feb 1, 2010 at 11:31 AM, Anil Kishore <anil.dai...@gmail.com>wrote: > >> This is clearly explained in the previous mail isn't it ? .. Anyway, >> sum of 1..n is S = n*(n+1)/2 . So, find the sum of all elements in the >> given input array, say the sum is T, this sum is almost same as S, its just >> less than S by the missing number. so, ( S - T ) will give the answer. Are >> you looking for something else ? >> >> - AK >> >> On Mon, Feb 1, 2010 at 4:24 AM, Banoo <banoo.rekh...@gmail.com> wrote: >> >>> hi, >>> can you help me solve the following problem? >>> >>> You are given an unsorted list of n-1 distinct integers from the range >>> 1 to n. Write a linear-time algorithm to find the missing integer. >>> >>> >>> Thanks >>> >>> -- >>> 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. >>> >>> >> >> >> -- >> Anil Kishore >> >> -- >> 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. > - -- 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.