Hard · Tries

Find Distinct Palindromic Substrings

Given a string s of lowercase letters, return the number of distinct non-empty substrings of s that are palindromes; each different string counts once, however often it occurs.

Examples

Example 1

s = "aba"

Output: 3 distinct palindromes

Example 2

s = "aabb"

Output: 4 distinct palindromes

Rebuild it in the studio

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Tries problems