Sir ji according to me every thing is fine in this code but i dont know why it is passing only 1 test case please help me sir;

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n;
cin>>n;
long long arr[100005];
for(long long i=0;i<n;i++) cin>>arr[i];

 do { 
    for(long long i=0;i<n;i++) cout<<arr[i]<<" ";
	cout<<endl;
} while (next_permutation(arr, arr+n)); 

}

@uditkumar652
Nhi yrr logic shi ni hai
Firstly N is max 10 so 10^5 ki need ni thi
You need to find all permutations
Next permutation krke nikaaloge toh time complexity bohot high hogi


See this for reference and try to extend it to arrays

sir i have my own sol which was tought us by our mentor but that recursive code is also not working fine an

sir i have my own sol which was tought us by our mentor but that recursive code is also not working fine and i have just copied the code from gfg and this is also not working

#include<bits/stdc++.h> using namespace std; vector v; void fun(char *a,int i) { if(a[i]==’\0’) { string str=""; for(int q=0;a[q]!=’\0’;q++) { str+=a[q]; } v.push_back(str); } for(int j=i;a[j]!=’\0’;j++) { swap(a[i],a[j]); fun(a,i+1); swap(a[i],a[j]); } } int main() { char a[100]; int n; cin>>n; int j; for(j=0;j<n;j++) cin>>a[j]; a[j]=’\0’; fun(a,0); vector v1; sort(v.begin(),v.end()); v1.push_back(v[0]); int i=1; while(i<v.size()) { if(v[i]!=v[i-1]) v1.push_back(v[i]); i++; } for(int i=0;i<v1.size();i++) { for(int h=0;h<v1[i].size();h++) { cout<<v1[i][h]<<" "; } cout<<endl; } return 0; }

my sol just above please tell what is wrong

@uditkumar652
Sure I’ll look into it
Send it on CB IDE with proper indentation please

sir ji i am in colaboration mode so you can go through the code

@uditkumar652
Buddy I need the code link to modify the code though right
So please send me the code link I don’t have it

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.

sir please guide me as i am not satisfied by your assistance

@uditkumar652
Yrr input integer hai tumne character array bnaya hua hai
Kaise chlega code

@uditkumar652
Hello Udit,
Just in case you are wondering why next_permuation() was not working, I have corrected your code.
you have to sort the integers before using next_permutation, because you have to generate all the permutations.
The link to the corrected code

Hey @abhinandankainth1999
Using next_permutation() for this question is not advisable since this question is about finding all permutations and using next_permutation() will waste unnecessary time and lead to high complexity
So since you have been assigned this doubt now I request you to help him with the permutation function

sir this code also giving all wrong test cases

@uditkumar652
Which ques are you trying to solve? finding the permutations of a string or finding the permutations of an array? https://hack.codingblocks.com/app/contests/1107/1098/problem The code I mentioned passed all the testcase on the above link. https://ide.codingblocks.com/s/241041?_ga=2.220667931.2006092954.1589277455-514560086.1580045254.

sir i am facing some problem sir the code link that you are providing and it is same as my code (means login) but ypu are saying that it passing all cases but in my case it is showing all cases wrong ans i dont know what is happning i am asking for the same from last 6 days but my issue is not resolved sir please give me some time and resolve it

I have sorted the array as well.

sir what should i do my code is not passing even a single test case