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
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
Why would xoring fail?
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
On Wed, Jan 4, 2012 at 9:56 AM, 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
how its 42??..didnt get it :(
--
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
Ok got itwill fail for the cases where the xor in the arrays
individually come to 0..
Saurabh Singh
B.Tech (Computer Science)
MNNIT
blog:geekinessthecoolway.blogspot.com
On Wed, Jan 4, 2012 at 10:13 AM, atul anand atul.87fri...@gmail.com wrote:
how its 42??..didnt get it :(
--
@Atul
For array (3 2 5 2 5)
Sum+= (sum of number from 1 to n) , n is each array element.
Sum=(1+2+3)+(1+2)+(1+2+3+4+5)+(1+2)+(1+2+3+4+5) =42
On 1/4/12, SAMM somnath.nit...@gmail.com wrote:
This may not work for the array having both +ve -ve numbers becoz
this logic is based on frequency
@Samm : dat woud be O(n^2) approach
--
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.