a={1,2,2,3,4}
b={1,2,3,3,4}
in this case???
elements are not equal but they certainly consist equal set of
integers(1,2,3,4) which is what question says.On Sun, Aug 22, 2010 at 7:53 AM, UMarius <[email protected]> wrote: > @Nikhil : I considered the array to be a linked list. xoring the > indexes helps when you don't know how many elements you have. > > Marius. > > On Aug 22, 5:04 am, Nikhil Agarwal <[email protected]> wrote: > > @marius Why are you xorring the indexes along with nos.?any special > reason? > > > > > > > > > > > > > > > > > > > > On Sun, Aug 22, 2010 at 7:19 AM, UMarius <[email protected]> wrote: > > > @Dave: I read the question correctly and for A = { 1 , 2} B = { 2 , 1} > > > the output is correct. > > > Maybe I didn't explain the steps correctly. This is the code: > > > > > for(int i = 0 ; i < arr1.Length ; i++) > > > { > > > arr1XOR ^= arr1[i]; > > > arr1XOR ^= i; > > > > > arr1SUM += arr1[i]; > > > arr1MUL *= arr1[i]; > > > } > > > > > for (int i = 0; i < arr2.Length; i++) > > > { > > > arr2XOR ^= arr2[i]; > > > arr2XOR ^= i; > > > > > arr2SUM += arr2[i]; > > > arr2MUL *= arr2[i]; > > > } > > > > > if(arr1XOR == arr2XOR && arr1SUM == arr2SUM && arr1MUL == > > > arr2MUL) > > > { > > > //SAME VALUES - IDENTICAL ARRAYS > > > } > > > else > > > { > > > //NOT IDENTICAL > > > } > > > > > Please correct me if I'm wrong. > > > > > Marius. > > > > > On Aug 22, 3:45 am, Dave <[email protected]> wrote: > > > > @UMarius: A = {1,2}, B = {2,1} fails your test. If you reread the > > > > original problem, you see that the question is not whether the arrays > > > > are identical (which is easily determined by simply comparing them > > > > element-by-element in O(n)), but whether they contain the same > values, > > > > possibly in a different order. > > > > > > Dave > > > > > > On Aug 21, 11:01 am, UMarius <[email protected]> wrote: > > > > > > > What about this? > > > > > > > 1. xor all elements of each array and their corresponding indexes & > > > > > sum all the elements of each array & mul all elements of each array > > > > > 2. if all results are the same then the arrays are identical > > > > > > > Nice to "meet" you all, I just joined and this is my first post :) > ... > > > > > > > > Given two arrays of numbers, find if each of the two arrays have > the > > > > > > same set of integers ? Suggest an algo which can run faster than > > > NlogN > > > > > > without extra space?- Hide quoted text - > > > > > > > - Show quoted text - > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Algorithm Geeks" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > > [email protected]<algogeeks%[email protected]> > <algogeeks%2bunsubscr...@googlegroups .com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/algogeeks?hl=en. > > > > -- > > Thanks & Regards > > Nikhil Agarwal > > Senior Undergraduate > > Computer Science & Engineering, > > National Institute Of Technology, > Durgapur,Indiahttp://tech-nikk.blogspot.comhttp:// > beta.freshersworld.com/communities/nitd > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<algogeeks%[email protected]> > . > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
