This may not work for the array having both +ve & -ve numbers becoz
this logic is based on frequency distribution of elements from 1 to
max(array elements) and if -ve num comes in here will disturb the
frequency distribution.

So this logic may work for only +ve and -ve elements array.

On 1/4/12, SAMM <somnath.nit...@gmail.com> wrote:
> I think this may works . needs verification.
>
> For the given array (3 5 2 5 2)
> For +ve number (N) take the sum from 1 to N .
> For -ve number (N) take the sum from -1 to N .
> And take take the cumulative sum ... For this array it comes 42 .
> Similarly check the sum for the second array . If it is same then we r done
> .
>
> On 1/3/12, atul anand <atul.87fri...@gmail.com> wrote:
>> There are two arrays.
>> int arr1[5] = { 3, 5, 2, 5, 2}
>> int arr2[5] = { 2, 3, 5, 5, 2}
>> The arrays will be called similar if they contain same number of elements
>> equally.
>> Write the pseudo code to check this ?
>> not allowed to use sorting and hashtable.
>>
>> naive approach O(n^2)
>>
>> NOTE: Xoring , sum wont work.
>>
>> we can use O(n) space , using index as elements in the array. but if it
>> has
>> negative number then it will fail for eg arr1 has -1,...  and arr2 has
>> 1,.....
>>
>> --
>> 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.
>>
>>
>
>
> --
> Somnath Singh
>


-- 
Somnath Singh

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