
Let s = “abbc”
Now In this example, Pam can make the following substrings:
a, b, b, c, ab, bb, bc, abb, bbc.
There are a total of 9 strings that she can gift Jim. Hence the answer is 9.
The first line contains a single integer ‘T’ denoting the number of test cases to be run. Then the test cases follow.
The first line of each test case contains a string ‘s’ denoting the ternary string.
For each test case, print a single integer “answer”, denoting the total number of strings she can make from the given string satisfying the given conditions.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 <= T <= 100
1 <= |S| <= 10^4, where |S| denotes the length of string S.
Time limit: 1 sec
In this approach, iterate through all the substrings from 0 to n-1 and count all the strings that satisfy the given conditions.
The steps are as follows:
In this approach, we will take two pointers, ‘i’, ‘j’, denoting the starting and ending points of a substring and check if that substring contains more than two different characters.
The steps are as follows: