Error in my code

Pls tell me the logical error in my code. It passes one testcase and fails two
The code is saved at:

for test case
2
abbbababbaba

answer should be 8 not 6
debug for this