Regarding backtracking

actually , i am stuck in the dry run of this problem as well as the process of the backtracking is little doubtful.
kindly clear me at this.

@shubhamssj5.ss did you understand the recursion tree?

@shubhamssj5.ss so we are not making a separate string for output, but making all changes in the input string only. Since it is a character array, it is always passed by reference. So any changes we make to the array, we have to reverse them too before the next recursive. This is called backtracking.
In the recursive case, we take 2 variables, i and j. We pass i through recursive calls, and j iterates from i till the end of string. First we swap a[i], a[j] and then we call the permute function for the remaining array, ie we have fixed the first element and now we call the function to permute the remaining array. But for our function to work perfectly, we need to fix a different character each time, right? and all the characters of the string need to be fixed at a particular position to generate corresponding permutations. so we “undo” our changes and again swap a[i], a[j] so our array is just the way it was passed to us by the previous call.

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.