FastPrepCount Distinct Palindromic Substrings

Count Distinct Palindromic Substrings

Roblox logoRoblox● HardNEW GRADOA
Learn

Problem statement

Count the distinct nonempty palindromic substrings of s. A substring is contiguous, and a palindrome reads the same forward and backward.

For this exercise, assume equal substring text is counted once, even when it occurs at different or overlapping positions. Return the number of different palindromic text values. The empty string contains none and returns 0.

Function

countDistinctPalindromes(s: String) → int

Examples

Example 1

s = "ababa"return = 5

The distinct values are a, b, aba, bab and ababa.

Example 2

s = "aaaa"return = 4

The four distinct values are a, aa, aaa and aaaa, regardless of repeated occurrences.

Example 3

s = ""return = 0

The empty substring is not counted.

Constraints

  • 0 <= s.length <= 5000.
  • Every character is a lowercase English letter.

More Roblox problems

See Roblox hiring insights
public int countDistinctPalindromes(String s) {
    // write your code here
}
s"ababa"
expected5
Checking account…