You are viewing a single comment's thread. Return to all comments →
My C Solution:
void minimumBribes(int q_count, int* q) {
unsigned int total = 0; unsigned int prev; unsigned int temp; int arr[q_count]; for(int i = 1; i <= q_count; i++) arr[i-1] = i; for(int i = 0; i < q_count; i++){ if(q[i] == arr[i]) continue; else if(q[i] == arr[i+1]){ temp = arr[i+1]; arr[i+1] = arr[i]; arr[i] = temp; total += 1; } else if(q[i] == arr[i+2]){ temp = arr[i+2]; arr[i + 2] = arr[i + 1]; arr[i+1] = arr[i]; arr[i] = temp; total += 2; } else { printf("Too chaotic\n"); return; } } printf("%d\n", total);
}
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
My C Solution:
void minimumBribes(int q_count, int* q) {
}