My code is giving correct output still test cases are not passing
what are you doing with this loop??
int flag=0;
for(int i=0;i<n-1;i++){
if(a[i]>a[i+1]){
flag=1;
}
else{
flag=0;
}
}
you have to simply use next_permutation function
it will handle all corner case
do it like this
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int t;cin>>t;
while(t--){
int n;cin>>n;
int arr[1000000];
for(int i=0;i<n;i++)cin>>arr[i];
next_permutation(arr,arr+n);
for(int i=0;i<n;i++)cout<<arr[i]<<" ";
cout<<endl;
}
return 0;
}
if you want to ask something about this feel free to ask
i hope this helps
if yes show your response with
and don’t forgot to mark doubt as resolved
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.