I tried the sample demo at Codility website, and posted my solution but I’ve a simple mistake but couldn’t determine it.
The problem is described here (The problem is only described please don’t care about the analysis there as that wasn’t not my solution)
http://codility.com/cert/view/certHNPV9B-7M4GAQR985B54VYF/details
my solution is here:
public static int min_router_peripherality ( int[] T ) {
// write your code here
int sum=0;
for(int i=0;i<T.length;i++) sum+= T[i];
int min = sum;
int index = 0;
int array [] = new int [T.length];
for(int i=0;i<T.length;i++) {
min = sum -T[i];
array[i] = min;
}
int x = array[0];
for (int i=0; i<array.length;i++)
{
if (array[i]<x)
{
x = array[i];
index = i;
}
}
return index;
}
What I see as mistakes are the following:
Here you treat
T[i]like some weight. But Node-Ids are no weights. Summing up node ids is useless.Then: The text says: “if T[P] = Q and P ≠ Q, …”. I don’t see anything which takes this into account.
Then: Not understanding the algorithm I tried a simple “line” like this:
The result is
8. But in a line the result should be somewhere in the middle.Therefore I doubt that the linked page shows the results of the code you have posted.