FastPrepCount Different Palindrome Substrings

Count Different Palindrome Substrings

Pure Storage logoPure Storage● MediumFULLTIMEOA
Learn

Problem statement

A string S is considered palindrome if it reads same way if spelled backwards, for example "nolemonnomelon", "ASANtaLivedAsAdeviLatNASA".

Any non-empty string has substrings that are palindromes. For example, in the string S = "hellolle", there are many of such "subpalindromes":

  • ellolle
  • ll, ll - note that these are two distinct substrings that only happen to be equal.
  • lol and lloll
  • And each single letter can be considered a palindrome - 8 of them.

Please write a function that, given a string S (only contains lowercase letters), returns number of different ways are there to pick a palindrome substring fro mS.

Function

countDifferentPalindromeSubstrings(s: String) → int

Examples

Example 1

s = "hellolle"return = 13

Output 13.

Example 2

s = "wowpurerocks"return = 14

each letter + "wow" + "rer"

More Pure Storage problems

See Pure Storage hiring insights
public int countDifferentPalindromeSubstrings(String s) {
  // write your code here
}
s"hellolle"
expected13
Checking account…