Count Palindromic Subsequences

Given a string of digits s, return the number of palindromic subsequences of s having length 5. Since the answer may be very large, return it modulo 10^9 + 7.

Note:

  • A string is palindromic if it reads the same forward and backward.
  • A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
Example 1
Inputs = "103301"
Output2
There are 6 possible subsequences of length 5, and two of them, both equal to "10301", are palindromic.
Example 2
Inputs = "0000000"
Output21
All 21 subsequences are "00000", which is palindromic.

Constraints

  • 1 <= s.length <= 10^4
  • s consists of digits.

Asked at 12 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate