i am not able to think about the approach of this question.is there any videos tutorial for this question?
and if not… please guide me the approach.
Approach for the question
@Mrinali_Mangal
Take a input as string and generate all possible permutations using Recursion . The method to do so has by discussed in Recursion and Backtracking section in your course.
As for how to remove the repeated permutations and arrange them in sorted order , store all the finally generated output strings in a vector which is declared in global and sort it using the sort( ) after all the recursive calls are done. Sort in the main( ) after the function call. Now all your output permutations are sorted. Start printing them one by one using a loop and skip the repeated permutations by comparing each permutation with its previous one.
Try this out and let me know if you need any help. If the whole approach is not clear and you are having trouble with understanding the sorting part , do the first part of the problem first i.e. generating the permutations . The rest can be handled later easily.
but that will use O(n!) space to store those permutations which is quite large .
@Mrinali_Mangal
Yes , you are right. This will require O(n!) space complexity and that is exactly why the constraint for length of string is given so low , since they know the complexity is already going to be high.
There is no other way to prevent repetitions without storing so we have to go with this approach or a similar approach but preventing this space complexity will not be possible.
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.