@Partha try with: A = {2, 2, 9} B= {1, 6, 6}
On Mon, May 21, 2012 at 7:08 PM, partha sarathi Mohanty < partha.mohanty2...@gmail.com> wrote: > a[] = [-1,-3,4,0,7,0,36,2,-3] > b[] = [0,0,6,2,-1,9,28,1,6] > b1[] = [0,7,0,36,4,-6,3,0,0] > b2[] =[-1,-3,11,0,0,0,35,0,0] > > suma = 42 proda = -84*72*3 > sumb = 51 prodb = -84*72*3 > sumb1 = 44 prodb1 = -84*72*3 > sumb2 = 42 prodb2 = 33*35 > > do the sum and prod operation w/o 0s and compare the values.. if both are > equal they are pormutations > if i am missing any corner cases related to 0 or -e numbers u can keep a > track of them while traversalO(N) and constant space > > > > On Mon, May 21, 2012 at 6:40 PM, karthikeya s > <karthikeya.a...@gmail.com>wrote: > >> No way u can do it in O(1) space and O(n) time.....sols above are not >> gonna work......yeah, it is possible in O(n) space and O(n) time. >> >> On May 20, 12:29 am, HARSHIT PAHUJA <hpahuja.mn...@gmail.com> wrote: >> > given 2 unsorted integer arrays a and b of equal size. Determine if b >> is a >> > permutation of a. Can this be done in O(n) time and O(1) space ? >> > >> > please help me with my solution >> > >> > suppose a -- 3 5 4 >> > b -- 4 3 5 >> > >> > now we replace a[i] with a[i]..th prime number and b with b[i] .. th >> prime >> > number >> > >> > now array a becomes 5 11 7 >> > array b becomes 7 5 11 >> > >> > now we take product of elements of array a and do the same with array b >> > elements >> > if product is equal then b is a permutation of a >> >> -- >> 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. > -- 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.