Unable to pass test case

Hey! I believe my code is correct. It is not O(n) as I am still unable to understand that approach but please help me debug this code.

approach is not correct
for the input
2
abbbaaaa

correct output
6
your code output
5

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.