I tried to do this question like this but some test cases are failing don’t know why?

@Sahil_Negi
for test case
2
abbbababbaba

answer should be 8 not 9
debug for this