Not able to idenfity the test cases where my code fails

can you check and tell me for which test cases my solution goes wrong

Sure,

But you have share your code for that.
STEPS:

  1. Open Coding Blocks IDE.
  2. Paste your code there.
  3. Save your code.
  4. Share the URL.

https://ide.codingblocks.com/s/105979 this is the code

Your code is failing for a test case like:
Example 1:
2
aaaaaaaaa
Your Output:
4
Expected Output:
9

Example 2:
1
abbaaa
Expected Output:
4
Your Output:
6

Please, review the logic that you are applying.
If you stuck and cannot find a better logic, let me knwo.
hope, this would help.