I am trying to solve this problem but I have a confusion regarding substrings to consider.
For example, if string is aabbcccaabbbccc and we want to count the number of substrings of length=2 that occur P=2 times. Should we consider bb and cc in the count?
I dont think so. Considering two substrings same if and only if both their starting and ending indices are same, I will say “bb” occurs 2 times in “bbb” as a substring and 1 more time at start, so it occurs for a total of 3 times.
But I checked successful solution for the input
aabbcccaabbbccc
1
2 2
The output is 3
I think this Q is taking things this way, “aa” “aa” is first 1, then “bb” and first 2 b’s in “bbb” as 2nd substring, (i.e. breaking “bbb” as “bb”[this substring is counted] +“b”) and so on. But i myself kind of disagree with this. I hope someone else is able to help you better