Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Count Different Palindromic Subsequences

Hard

Topics
StringDynamic Programming

Given a string s, return the number of different non-empty palindromic subsequences in s, taken modulo 10^9 + 7. Two subsequences are different if there is some index where they differ.

Example 1

Input:  s = "bccb"
Output: 6

Example 2

Input:  s = "abcd"
Output: 4

Example 3

Input:  s = "aaa"
Output: 3

Constraints

  • 1 <= s.length <= 12
  • s consists of characters 'a', 'b', 'c', or 'd'.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access