let a string s=“aaaa”

there are 6 good string as:

3 subarray of length 2:[aa] [aa] [aa]

2 subaaray of length 3:[aaa] [aaa]

1 subarray of length 4:[aaaa]

So for string of only one character there will be l*(l+1)/2 where l=length of subarray of same character

Now for string s=“aaabbb”

calculate subarray of character ‘a’ and ‘b’.add simply.

last for string s=“abbba”

length of subarray of character b and check if character before initial ‘b’ and after final ‘b’ is same or not and add+1 to answer

here is my solution:https://www.codechef.com/viewsolution/15926610