@Gaurav: you are taking ia and ib as int so they will have 32 bits in
Java. So you can not set the bits for numbers in the array greater
than 32.
e.g if you have a[i]=59876 so you would want to set the 59876th bit in
ia : ia=ia | (1<<59876) but that is not possible. How do you handle
this?
Also how do you handle the case for negative numbers??
What I think we can do is:
If we take ia and ib as BigInteger in Java then we don't have that
constraint of 32 bits. I tried it out it works for large no as 35000
instantly.
But that still doesn't solve the problem of -ve numbers.

regards
Abhishek Khanna

On May 20, 1:42 am, GAURAV CHAWLA <togauravcha...@gmail.com> wrote:
> we can do it bitwise...
>
> i can set the corresponding bit by 1 of any int ...
> lets take
> int ia,ib=0;
> and set the a[i]th bit of ia as 1 ,
> and similar for  bth array and ib ...
>
> and finally check.. if(ia==ib){permutation of each other}
>
> hope this will work..
>
> On Sun, May 20, 2012 at 1:39 AM, malay chakrabarti <m1234...@gmail.com>wrote:
>
>
>
> > dat defeats the o(1) space constraint. :-)
> > On May 19, 2012 8:05 PM, "HARSHIT PAHUJA" <hpahuja.mn...@gmail.com> wrote:
>
> >> @malay ---  we can do it by precomputing the prime arrays
> >> ....................
>
> >> On Sun, May 20, 2012 at 1:10 AM, malay chakrabarti 
> >> <m1234...@gmail.com>wrote:
>
> >>> method is ryt but to find ith prime u cannot to it in constant time.
> >>>  On May 19, 2012 7:30 PM, "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.
>
> >> --
> >> HARSHIT PAHUJA
> >> M.N.N.I.T.
> >> ALLAHABAD
>
> >>  --
> >> 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.
>
> --
> Regards,
> GAURAV CHAWLA
> +919992635751
> +919654127192

-- 
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