Is that even possible? I've tried to use the following code, but it's obviously wrong:
#include <stdio.h>
int scrambled( unsigned int a[], unsigned int b[], unsigned int len)
{
if (len=0)
{
retu 1;
}
else
{
int sumA,sumB,i;
for (i=0; i<len; i++)
{
sumA+=a[i];
}
for (i=0; i<len; i++)
{
sumB+=b[i];
}
if (sumA==sumB)
{
retu 1;
}
else
{
retu 0;
}
}
}
int scrambled( unsigned int a[], unsigned int b[], unsigned int len );
I assumed that two arrays with the same sum of values would also have the same values, but this is not the case. {2,2} and {3,1} have the same sum, but not the same values.
Is there any way I can check if, in another words, one array is a permutation of another with linear complexity time?
