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.
- Prepare
- Algorithms
- Implementation
- Larry's Array
- Discussions
Larry's Array
Larry's Array
Sort by
recency
|
338 Discussions
|
Please Login in order to post a comment
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )
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;
} }
}
here what I am doing I am counting total number of inversion pairs . If they are Even then it is possible to get sorted array after rotating triples. since after rotating or transposing the array the total number of inversions will either increase by 2 or decrease by 2 so if total number of inversions are even then eventually after rotating after some point you'll get inversions 0 which implies that array is sorted but in case you have total inversions odd you can never have 0 inversions after rotating or transposing
Python3
def larrysArray(A):