Merge sort using recursion

every approach is showing TLE,what to do

hello @argus

pls share ur mergesort code with me .

#include using namespace std; #define ll long long void merge(ll int a[],ll int s,ll int e){ ll int mid=(s+e)/2; ll int i=s; ll int j=mid+1; ll int k=s; ll int temp[1000]; while(i<=mid&&j<=e){ if(a[i]<a[j]){ temp[k++]=a[i++]; } else{ temp[k++]=a[j++]; } } while(i<=mid){ temp[k++]=a[i++]; } while(j<=e){ temp[k++]=a[j++]; } for(int i=s;i<=e;i++){ a[i]=temp[i]; } } void mergesort(ll int a[],ll int s,ll int e){ if(s>=e){ return ; } ll int mid=(s+e)/2; mergesort(a,s,mid); mergesort(a,mid+1,e); merge(a,s,e); } int main(){ ll int n; cin>>n; ll int a[n]; for( int i=0;i<n;i++){ cin>>a[i]; } mergesort(a,0,n-1); for(int i=0;i<n;i++){ cout<<a[i]<<" "; } }

save it here->https://ide.codingblocks.com/
and then share its link

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.