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 <[email protected]>wrote:
> dat defeats the o(1) space constraint. :-)
> On May 19, 2012 8:05 PM, "HARSHIT PAHUJA" <[email protected]> wrote:
>
>> @malay --- we can do it by precomputing the prime arrays
>> ....................
>>
>> On Sun, May 20, 2012 at 1:10 AM, malay chakrabarti <[email protected]>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" <[email protected]>
>>> 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 [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.
>>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>> 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 [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.
>>
> --
> 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.
>
--
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 [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.