pyassistant

Distinct Palindromic Subsequences (hard)

Count distinct non-empty palindromic subsequences of a string. A subsequence is obtained by deleting zero or more characters (not necessarily contiguous). Two subsequences are considered different if their string values differ. Return the count modulo 10^9+7. Example: s = "bccb". The distinct non-empty palindromic subsequences are: "b", "c", "bb", "cc", "bcb", "bccb" — total 6. Given a string s (1 <= len(s) <= 1000, consisting of lowercase letters), compute the number of distinct non-empty palindromic subsequences modulo 1_000_000_007.

Example:

Input:
("bccb",)
Output:
6

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.