Doubt in sanket and strings

Please help me out with what’s wrong in my code.

Here it is - https://ide.codingblocks.com/s/381750

for test case
2
abbbababbaba

answer should be 8 not 9
debug for this

But nowhere in the question it’s mentioned that it should be consecutive. According to the question, answer should be 9 only.

Sorry, I got your point. I’ve dropped some queries over the chat, please help me out.