What is wrong in my code it’s giving WA? code link: https://ide.geeksforgeeks.org/ly3USFo26i
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
long long n,flag=0;
cin>>n;
long long a[n],i;
for(i=0;i<n;i++)
cin>>a[i];
for(i=n-1;i>0;i–)
{
if(a[i]>a[i-1])
{
flag=1;
long long temp=a[i];
a[i]=a[i-1];
a[i-1]=temp;
sort(a+i,a+n);
break;
}
}
if(flag)
{
long long num=0;
for(i=0;i<n;i++)
num=num*10+a[i];
cout<<num;
}
else
cout<<"-1";
cout<<"\n";
}
return 0;
}