
The first line contains an integer ‘T’, which denotes the number of test cases to be run. Then the test cases are as follows.
The first and the only line of each test case contains the string 'STR'.
For each test case, print an integer denoting the count of homogenous substrings.
Print the output of each test case in a separate line.
You don’t need to print anything; It has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= |STR| <= 10000
String STR contains only lowercase letters
Where '|STR|' denotes the length of the string.
Time limit: 1 sec
The basic approach is to create all possible substrings from the given string and then count the number of homogenous substrings from them.
Algorithm:
The basic idea behind this approach is to find the length of the same characters before the current character and add it to the total count of homogenous substrings. Let us understand this better with the help of an example:
Let “STR” = aabbb
Now we will start traversing,
=> “current” = a, continuousCharacterCount = 1, so adding into result, result = 1
=> next character = a, continuousCharacterCount = 2, adding into result, result = 3
=> next character = b, continuousCharacterCount = 1, adding into result, result = 4
=> next character = b, continuousCharacterCount = 2, adding into result, result = 6
=> next character = b, continuousCharacterCount = 3, adding into result, result = 9