Skip to content

Instantly share code, notes, and snippets.

@davethomas11
Created November 3, 2015 06:45
Show Gist options
  • Save davethomas11/5c4a31b2200d3bbec347 to your computer and use it in GitHub Desktop.
Save davethomas11/5c4a31b2200d3bbec347 to your computer and use it in GitHub Desktop.
int solution(int A[], int N) {
// write your code in C99
int minimal = 1;
int i = 0;
int * array = calloc(N + 1, sizeof(int));
for (; i < N; i++) {
if (A[i] > 0 && A[i] <= N && array[A[i]] == 0) {
array[A[i]] = 1;
}
}
for (i = 0; i < N; i++) {
if (array[i+1] == 0) {
free(array);
return i + 1;
}
}
free(array);
return N + 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment