We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Special String Again

Special String Again

Problem
Submissions
Leaderboard
Discussions
Editorial

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.

Example

contains the following special substrings: .

Function Description

Complete the substrCount function in the editor below.

substrCount has the following parameter(s):

  • int n: the length of string s
  • string s: a string

Returns
- int: the number of special substrings

Input Format

The first line contains an integer, , the length of .
The second line contains the string .

Constraints


Each character of the string is a lowercase English letter, .

Sample Input 0

5
asasd

Sample Output 0

7 

Explanation 0

The special palindromic substrings of are

Sample Input 1

7
abcbaba

Sample Output 1

10 

Explanation 1

The special palindromic substrings of are

Sample Input 2

4
aaaa

Sample Output 2

10

Explanation 2

The special palindromic substrings of are

Author

rock19

Difficulty

Medium

Max Score

40

Submitted By

67080

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature