Tricky permutatons

how to remove the repeated permutations?
this is my code : https://ide.codingblocks.com/#/s/15140
question link: https://hack.codingblocks.com/contests/c/452/737

You can avoid to swap if same character reaches like when a[i] is same as a[j]

there are 2 ways
1.
you have to avoid swapping when there are same character but their position are different
like ABCA when a[i]==a[be] but i!=be don’t swap .

  1. you can store the each output in a set Ds then using a iterator u can iterate on set it will automatically delete the same ,there is no need to avoid swapping in this case

the code worked fine using set approach, thank you!
but I tried using the first approach, it is not working for more than 3 elements : https://ide.codingblocks.com/#/s/15614
please tell me how to do this

Heyy ! wen you are inserting the new strings in your vector then you should first check wheather this new string is alredy there or not . It may possible that one strings have same permutations as in AABB . Just check it before inserting it into your vector .

1 Like