Practice/Salesforce/Leetcode 730. Count Different Palindromic Subsequences
CodingMust
Given a string containing only the characters 'a', 'b', 'c', and 'd', determine how many distinct non-empty palindromic subsequences exist within it. A subsequence is formed by deleting zero or more characters from the original string without changing the relative order of remaining characters. Two subsequences are considered distinct if they differ in at least one position.
Since the answer may be very large, return the result modulo 10^9 + 7.
Example 1:
` Input: s = "bccb" Output: 6 Explanation: The 6 distinct palindromic subsequences are:
Example 2:
Input: s = "abcdabcd" Output: 104 Explanation: Many palindromic subsequences can be formed, including single characters, pairs like 'aa', 'bb', and more complex patterns like 'abcba', 'abdba', etc.
Example 3:
Input: s = "a" Output: 1 Explanation: Only one palindromic subsequence: 'a'