Special String Again

Special String Again


A string is said to be a special string if either of two conditions is met:

All of the characters are the same, e.g. aaa. All characters except the middle one are the same, e.g. aadaa. A special substring is any substring of a string which meets one of those criteria. Given a string, determine how many special substrings can be formed from it.

For example, given the string s= mnonopoo, we have the following special substrings:

{m, n, o, n, o, p, o, o, non, ono, opo, oo}

Read more on the challenge page…

Problem Analysis and Solution

My Solution

I’m providing the solution for Python and JS, please leave on the comments if you found a better way.


Subscribe to my weekly newsletter for developers and builders and get a weekly email with relevant content.

    You can learn more about what to expect in these emails here.