What is wrong with this code

#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t!=0)
{
int n,count=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];

	for(int i=0;i<n-1;i++)
	{
		if(a[i]>a[i+1])
		count++;
	}

	if(count==n-1)
	{
		sort(a,a+n);
		for(int i=0;i<n;i++)
		cout<<a[i];
	}

	else
	{
		next_permutation(a,a+n);
		for(int i=0;i<n;i++)
		cout<<a[i];
	}

	t--;
}

return 0;
}

Using next_permutation destroys the purpose of this problem. Try to implement your own next_permutation function.

You are not considering when array contain equal elements.
And also try to do it without using the next_permutation function.

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.