@tishya_goyalso currently what you are doing is that if you print valid characters and check for repeats. if you come across a repetition, you jump 2 indices, instead of 1. But this wont work if there are odd number of repetions, because for eg,
aaa
now we call for arr, we print arr[0], and see that a[0] == a[1], so we call the function for arr+2, now the character is a, but it will be printed as well, because it does not fail any conditions.
What you can alternatively do is, actually delete the repetitive element from the array, and next time call for arr only (because now the next element will be shifted 1 space backwards because of deletion, and we have to check that too. if we call for arr+1 then we would have moved one space forward and wont be able to check it against the current element). look at the below example to make sense of what i just said
for eg in aaabbbccc
you come across a, you see that next element is also a, so you delete either the next element or the current element and the string becomes aabbbccc. call for arr again.
again you are at the same a, you see next element is a, you delete a, the string becomes abbbccc
now a != b, so you can call for arr+1