Not passing all test cases

@Sunkumsav
This code will work when there are no repeated characters in a string. But it wouldnt work when repeated characters exist in the string. It can be solved by following the above steps:

  1. Dont swap two characters which are same, this would lead to same outputs.
  2. Dont swap a character again with a character with which it had been swapped with before.

If my answer was able to resolve your query, please mark the doubt as resolved.

I have checked as you said but it is till failing in some test cases

@Sunkumsav
Send me the updated code.

@Sunkumsav
This is the updated code. Please refer to it and revert in case you face any difficulty. I have used a vector in place of a set because the time complexity increase because a set maintains its elements in a sorted order.

If you face any difficulty, please revert.