Skip to content

Instantly share code, notes, and snippets.

@rahulkmr
Created February 7, 2010 07:42
Show Gist options
  • Save rahulkmr/297293 to your computer and use it in GitHub Desktop.
Save rahulkmr/297293 to your computer and use it in GitHub Desktop.
int duplicate(int a[], int n)
{
int sum = 0, num = n - 1;
doulbe ideal_sum = (num * (num + 1)) / 2;
int i;
for (i = 0; i < n; i++) {
sum += a[i];
}
return sum - ideal_sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment