Permutation of a string

question–>
https://practice.geeksforgeeks.org/problems/permutations-of-a-given-string/0
code–>


it is showing segmentation fault

Add return statement in base case @sheikhhaji18

    if(i==s.length()){
        v.push_back(s);
        return ;//added this
    }

Now try to debug logically :slight_smile:

void fun(string s,int i,vector<string> &v){

    if(i==s.length()){

        v.push_back(s);

        return ;

    }

    for(int j=i;j<s.length();j++){  //j=i updated

        swap(s[i],s[j]);

        fun(s,i+1,v);

        swap(s[i],s[j]);

    }

    

}

Now it is passing all testcases
Man i did this for third time still i cannot code it, i am just mugging up things ,i should try to dry run; and learn the concept;thanks

1 Like

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.