Logic to count the subsequent string?

i am able to print the subsequent string

What is the problem with your code ? Pls share your code here