Skip to content

Instantly share code, notes, and snippets.

@davethomas11
Created November 5, 2015 04:59
Show Gist options
  • Save davethomas11/f6fa8e84c35b46b21592 to your computer and use it in GitHub Desktop.
Save davethomas11/f6fa8e84c35b46b21592 to your computer and use it in GitHub Desktop.
struct Results solution(int N, int A[], int M) {
struct Results result;
// write your code in C99
int * c = calloc(N, sizeof(int));
int max = 0;
int latestMax = 0;
int i = 0;
int idx = 0;
for (; i < M; i++) {
if (A[i] == N + 1) {
max = latestMax;
} else {
idx = A[i] - 1;
if (c[idx] < max) {
c[idx] = max;
}
c[idx]++;
if (c[idx] > latestMax) {
latestMax = c[idx];
}
}
}
for (i = 0; i < N; i++) {
if (c[i] < max) {
c[i] = max;
}
}
result.C = c;
result.L = N;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment