Special String Again

Special String Again - A HackerRank challenge solution


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.

If you liked what you saw, please support my work!

Juan Cruz Martinez - Author @ Live Code Stream

Juan Cruz Martinez

Juan has made it his mission to help aspiring developers unlock their full potential. With over two decades of hands-on programming experience, he understands the challenges and rewards of learning to code. By providing accessible and engaging educational content, Juan has cultivated a community of learners who share their passion for coding. Leveraging his expertise and empathetic teaching approach, Juan has successfully guided countless students on their journey to becoming skilled developers, transforming lives through the power of technology.