C, 84 bytes
c[' '],r,*p,*s,*e;f(){for(p=s;p<e;)c[*p++]++;while(s<e)if(c[*s++]-2)r=1;return r;}
The variable s
should point to the beginning of the array, and e
should point to the end. Note that after f()
is called, c
must be reset to 0s before it can be called again. Also, this might not work on all computers, because I'm pretty sure multi-byte characters are implementation-defined...
If I/O is very flexible, and outputting to a variable is enough, the return r;
is unnecessary, and it can be reduced to 75 bytes.
De-golfed:
int counts[100001], return_value;
int f(int *start, int *end) {
int *ptr;
for (ptr = start; ptr < end; ptr++)
counts[*ptr]++;
for (ptr = start; ptr < end; ptr++) {
if (counts[*ptr] != 2) {
return_value = 1;
}
}
return return_value;
}