How To Minimize a String(WA)

Go through the Link Of the question b4 reading the follwing lines
Link of the Question:-

In The question it has been asked that we are allowed to perform only one ty[e of operation i.e:
Choose any position in the string, remove the character at that position and insert it back to any other place in the string.
The above solution is possible if only one opeartion is possible
My solution:
Following strictly that only one opearation si possible I am getting WA.
Plz help

Your logic is not completely right.

Consider the



for this input output must be



But your code’s output is “AABCD

what your code is doing, if same character (character that to be replaced) exist in the input more than once then it will not displaying that character again. Do correct it.

Hope it helps.