You are viewing a single comment's thread. Return to all comments →
i don't know why this is showing TLE. Can anyone optimise this...
#include <bits/stdc++.h> using namespace std; int insertionSort(int array[], int n) { int count = 0; for(int i = 1; i < n; i++){ int res = array[i]; int j = i-1; while(j>=0 && array[j]>res){ array[j+1] = array[j]; j--; count++; } array[j+1] = res; } return count; } int main() { int t; cin >> t; while(t--){ int n; cin >> n; int array[n]; for(int i = 0; i < n; i++){ cin >> array[i]; } cout << insertionSort(array, n) << endl; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort Advanced Analysis
You are viewing a single comment's thread. Return to all comments →
i don't know why this is showing TLE. Can anyone optimise this...