Getting wrong ans

my code is passing all the test cases luckily but i am running my code for input (aqweed) the expected output is
(aqwed) but the output is (aqweed) please tell me how to correct my code and please correct the glitch of this code

You can take an extra string variable to maintain the result.
Check this approach https://ide.codingblocks.com/s/266791

i understand your approach but why i am getting this glitch and still passing all the test cases

The test cases are weak for this question.
Your code is failing for all these type of inputs abba ,abbba etc…Dry run your code with these cases and check…