Not getting all permutations in my code.... | SoloLearn: Learn to code for FREE!

+4

Not getting all permutations in my code....

Please help me find my mistakes 🙏 https://code.sololearn.com/ca17A25a1717/?ref=app

5/17/2021 9:38:07 AM

[ ]

10 Answers

New Answer

+4

Instead of pushing full swapped s into recursion, put only a sliced tail into the the recursion. For inserting into Set, you only need to insert under the condition index == n at beginning of soln() code block.

+4

ok... permuations in C++ is actually easy just use std::next_permutation(begin(x),end(x)); ........... /*side notes*/ now few things i dont like in the code for(set<string>::iterator i=Set.begin();i!=Set.end();i++) { cout<<*i<<'\n'; } can be changed to for(auto i: Set) { cout<<i<<'\n'; } also ios_base::sync_with_stdio(false) and cin.tie(NULL) i mean why change this if it aint broken? there s a reason most people dont touch this function is because the default is fine.

+4

congrats by the way for figuring out your own algorithm for it.

+2

ChillPill ty for replying and for ur suggestions ..... I knew about the function next_permuation() it's just that I'm still in learning phase so don't want to use built-in functions rather I would try to code them up And I couldn't use auto feature because I was coding in dev- c++ which was working in c++98 mode .... XD Aggghh I guess I should have changed some stuff before posting the code but still ty for everything

+2

I got my mistake...... While again calling the soln function I should have used index+1 as a parameter instead of i +1 ......because index is responsible for slicing I is for swapping elements

+1

👍

0

ChillPill Hatsy Rei Gordon pls help 🙏

0

Gordon I tried ur soln but still no luck...... I believe u meant this https://code.sololearn.com/cVAzPJdl4lAh/?ref=app

0

Gordon ty for replying..... I forgot to mention that earlier.....sry

0

ChillPill sir you are accurately or absolutely at the right way to learn i.e., not only be aware of what a built-in function returns but also to figure it out how it would be created in the back-end or the hidden phase which we call built-in functions .