Given an array A
of N
integers we draw N
discs in a 2D plane, such that i-th disc has center in (0,i)
and a radius
Well, I adapted Falk Hüffner's idea to c++, and made a change in the range. Opposite to what is written above, there is no need to go beyond the scope of the array (no matter how large are the values in it). On Codility this code received 100%. Thank you Falk for your great idea!
int number_of_disc_intersections ( const vector &A ) {
int sum=0;
vector start(A.size(),0);
vector end(A.size(),0);
for (unsigned int i=0;i=A.size()) end[A.size()-1]++;
else end[i+A[i]]++;
}
int active=0;
for (unsigned int i=0;i10000000) return -1;
active+=start[i]-end[i];
}
return sum;
}