Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count Different Palindromic Subsequences

XPChallenge Points: 30
levelLevel: Hard

Given a string s, your task is to determine how many unique non-empty palindromic subsequences can be formed from it.
A subsequence is created by removing zero or more characters without reordering the remaining ones.

A string is considered a palindrome when it reads the same forward and backward.

Two subsequences are treated as different if at least one position contains a different character.

Because the count can become extremely large, return the result modulo 1,000,000,007.

Example 1:

Input: s = "aaa"

Output: 3

Explanation:

The unique palindromic subsequences are: "a", "aa", "aaa".

Example 2:

Input: s = "abca"

Output: 5

Explanation:

Unique palindromic subsequences are: "a", "b", "c", "aa", "aca".

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result