Tap here to switch tabs
Problem
Submissions

Problem: Count Different Palindromic Subsequences

med
30 min
Try to solve the Count Different Palindromic Subsequences problem.

Statement

Given a string s, return the number of distinct nonempty palindromic subsequences in s.

Since the answer can be very large, return it modulo 109+710^9 + 7.

A subsequence of a string is obtained by deleting zero or more characters from the original string without altering the relative order of the remaining characters.

A string is palindromic if it reads the same forwards and backwards.

Two subsequences are considered distinct if their string values are different.

Constraints:

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s[i] is either 'a', 'b', 'c', or 'd'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Different Palindromic Subsequences

med
30 min
Try to solve the Count Different Palindromic Subsequences problem.

Statement

Given a string s, return the number of distinct nonempty palindromic subsequences in s.

Since the answer can be very large, return it modulo 109+710^9 + 7.

A subsequence of a string is obtained by deleting zero or more characters from the original string without altering the relative order of the remaining characters.

A string is palindromic if it reads the same forwards and backwards.

Two subsequences are considered distinct if their string values are different.

Constraints:

  • 1≤1 \leq s.length ≤1000\leq 1000

  • s[i] is either 'a', 'b', 'c', or 'd'.