Algorithm:

1. Given array A[], Set B[], sum=0,repeatedNumb=0;
2. for index i to n
    B[ A[i] -1 ] = B[ A[i] -1]+1
    sum=sum+A[i]
3. for index i to n
     if B[i]=2
             repeatedNumb=i+1
             break;

4. Nsum=n*(n+1)/2
5. missingNumb=Nsum+repeatedNumb-sum


Step-2 to3, finding the repeatedNum, complexity=O(n)+O(n)
Step4: finding the Nsum, complexity=O(n) if formula is not used


Thanks,
Krishna



On Jul 18, 6:26 pm, SkRiPt KiDdIe <anuragmsi...@gmail.com> wrote:
> > @Nishant:
>
> >>> 1 4 5 4 5    n=5
>
> >>> 1 2 3 4 5
>
> >>> after xor i.e. your x1 answer contains (2^3^4^5).The missing elements are
> >>> included in xor as well along with repeating elements.
>
> >>> Hope now you got it. You are giving solution for a question which i have
> >>> defined in previous post. and your algo will fail when
> >>> the final xor has no set bit i.e.  same number is being repeated twice.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@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.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@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.

Reply via email to