I think my code is right! why does it give error?

#include
using namespace std;

void merge(long long int *arr , long long int s ,long long int e){
long long int mid = (s+e)/2;
long long int i=s;
long long int j = mid+1;
long long int k=s;

long long int temp[10000];
while(i<=mid && j<=e){
	if(arr[i]<arr[j]){
		temp[k++]=arr[i++];
	}else{
		temp[k++]=arr[j++];
	}
}
while(i<=mid){
	temp[k++]=arr[i++];
}
while(j<=e){
	temp[k++]=arr[j++];
}
for(i=s;i<=e;i++){
	arr[i]=temp[i];
}

}

void mergesort(long long int *arr ,long long int s ,long long int e){
long long int mid = (s+e)/2;
mergesort(arr,s,mid);
mergesort(arr,mid+1,e);
merge(arr,s,e);
}
int main() {
long long int n;
cin>>n;
long long int arr[10000];
for(long long int i=0;i<n;i++){
cin>>arr[i];
}
mergesort(arr,0,n-1);
for(long long int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
return 0;
}

Hey @chetan_aggarwalbX1 please share your code using ide.codingblocks.com :grinning:

This is my code! I think it is alright , there is surely some minute problem

Hey @chetan_aggarwalbX1 you can typedef long long int ll, and now your ll will acts as long long int
Moreover there where small mistakes, I have added comments for that. Now it will work fine :slight_smile:

It is working fine now ! Thankyou! And yes I know I can typedef it , I just added it afterwards because I thought problem was long long . so used it rightaway

Wait it doesn’t still work on any of the testcase

That’s fine , if your doubt is resolved do give this post a like :slight_smile:

Which test case is it failing?

It works fine on sample testcase , but fails all the testcases upon submission

Constraint was the problem , I was able to fix it! Thanks for the help.

If you liked my explanation, do press like button :slight_smile:

1 Like

At last, Chetan was able to fix the issue. I am also confused it has minor mistakes but experts know well because I am fresher work in CETPA I will try.