Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

Special Palindrome Again Challenge

Sharing is caring!

Problem Statement
A string is said to be a special palindromic 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 specialpalindromic substring is any substring of a string which meets one of those criteria. Given a string, determine how many special palindromic substrings can be formed from it.

For example, given the string s=mnonopoo, we have the following special palindromic substrings: {m, n, o, n, o, p, o, o, non, ono, opo, oo}.

Function Description
Complete the substrCount function. It should return an integer representing the number of special palindromic substrings that can be formed from the given string.

substrCount has the following parameter(s):
* n: an integer, the length of string s
* s: a string

Input Format
The first line contains an integer, n, the length of s.
The second line contains the string s.

Constraints
* 1 \le n \le 10^6
* Each character of the string is a lowercase alphabet, ascii[a-z].

Sample Input 0

Sample Output 0

Explanation 0
The special palindromic substrings of s=asasd are {a, s, a, s, d, asa, sas}.

Solution