pls send to me the solution
No editorial for this problem
Hello @Anchal,
I am not allowed to send the entire code to the students.
But I can help you with your errors.
I would suggest you to first write a code that prints all the permutations of the given string (including the redundant one).
Then, try to modify the same for nonredundant permutations.
Try to write code and share it with me, if it won’t work.
But first, try hard to do it yourself.
Hope, this would help.
The code you have sent is correct but the if conditions are not checking for all the possible cases.
For example:
abab
Suppose at first iteration i=0;
- you would swap with b i.e. k=1, as it is satisfying the first part of if condition.
- you would not swap for k=2 i.e , as it does not satisfy any of the if condition.
Now, comes the logical error:
3. for k=3 i.e. b , you would again perform swapping which will cause redundancy of permutations.
Solution:
Inside the for loop, before executing all three statements,
Check if a[k] does not already exist in array between i and k index (including i).
All you have to do is this simple check to avoid redundancy.
Suggestion:
Create a function for the same and return true if it does not exist, else false.
For true, execute the three statements of for loop.
Hope, this would help.
Give a like, if you are satisfied.
Please, mark it as resolved if your doubt is solved.
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.