We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Coding C
char* larrysArray(int A_count, int* A) {
int temp = A_count, idx = 0, dich = A_count-1, step2;
//dua tung gia tri lon nhat ve vi tri dich.
while (temp >= 3){
for (int i = 0; i < A_count; i++){
if (A[i] == temp){
idx= i; break;
}
}
step2 = (dich-idx+1)/2; //so buoc lui 2.
for (int i = 1; i < step2; i++){
lui2(A, idx); idx+=2;
}
if ((dich-idx) %2==1){
tien1(A, idx); idx--;
}
lui2(A, idx); idx+=2; // lui not lan cuoi cung.
temp--; dich-- ;//giam dich va gia tri lon nhat.
}
char *res = (char*)malloc(4* sizeof(char));
if (A[0] == 2) strcpy(res, "NO");
else strcpy(res, "YES");
return res;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Larry's Array
You are viewing a single comment's thread. Return to all comments →
Coding C char* larrysArray(int A_count, int* A) { int temp = A_count, idx = 0, dich = A_count-1, step2; //dua tung gia tri lon nhat ve vi tri dich. while (temp >= 3){ for (int i = 0; i < A_count; i++){ if (A[i] == temp){ idx= i; break;
} }
}