Created
November 5, 2015 04:59
-
-
Save davethomas11/f6fa8e84c35b46b21592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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