@ankit...i m assuming that array of size n contains n-2 elements with 2 elements missing
On Mon, Jul 18, 2011 at 6:07 PM, SAMMM <somnath.nit...@gmail.com> wrote: > #include<stdio.h> > int main() > { > > int a[]={1,2,3,5,2}; // 2 isrepeated and 4 is missing > int i=0,x=0,j=0,bit; > while(i<5) > { > j^=i+1;j^=a[i]; > i++; > } > > bit=j&~(j-1); //set bits > > i=0;j=0; > > while(i<5) > { > if(bit&(i+1)) x^=(i+1); //two set are needed to iterate > else j^=(i+1); //two set are needed to iterate > i++; > } > i=0; > while(i<5) > { > if(bit&a[i]) x^=a[i]; //two set are needed to iterate > else j^=a[i]; //two set are needed to iterate > i++; > } > > printf("%d %d",x,j); > return 0; > } > > Hav a look .... The trick is in the set bit [ bit=j&~(j-1); //set > bits] > > On Jul 18, 4:31 pm, TUSHAR_MCA <tusharkanta.r...@gmail.com> wrote: > > Given an array of size n. It contains numbers in the range 1 to n. > > Each number is present at least once except for 2 numbers. Find the > > missing numbers ? > > -- > 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.