`{"id":"77e40ec8-87b5-4a34-a9de-687b2009ef5c","name":"Count Of Distinct Palindromic Subsequences ","description":"1. You are given a string.\r\n2. You have to print the count of distinct and non-empty palindromic subsequences in the given string.\r\n3. Two sequences s1 and s2 are distinct if here is some i, for which ith character in s1 and s2 are different.\r\n\r\nNote -> String contains only lowercase letters.\r\n -> The answer will be in the integer range only.","inputFormat":"A String","outputFormat":"An Integer","constraints":"1 &lt;= length of string &lt;= 10000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str) {\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"bccb","sampleOutput":"6\r\n","questionVideo":"https://www.youtube.com/embed/fvYlinirmFg?end=97","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"575abc6f-ead5-4fce-86c3-24826248e822","name":"Count Of Distinct Palindromic Subsequences ","slug":"count-of-distinct-palindromic-subsequences","type":1}],"next":{"id":"8a1c09a9-5364-4779-8263-e960f54f7be7","name":"Count of distinct palindromic subsequences MCQ","type":0,"slug":"count-of-distinct-palindromic-subsequences-mcq"},"prev":{"id":"a6681732-1f58-4852-8344-ed9189e274d5","name":"Count Distinct Subsequences","type":3,"slug":"count-distinct-subsequences"}}}`

# Count Of Distinct Palindromic Subsequences

1. You are given a string. 2. You have to print the count of distinct and non-empty palindromic subsequences in the given string. 3. Two sequences s1 and s2 are distinct if here is some i, for which ith character in s1 and s2 are different. Note -> String contains only lowercase letters. -> The answer will be in the integer range only.

`{"id":"77e40ec8-87b5-4a34-a9de-687b2009ef5c","name":"Count Of Distinct Palindromic Subsequences ","description":"1. You are given a string.\r\n2. You have to print the count of distinct and non-empty palindromic subsequences in the given string.\r\n3. Two sequences s1 and s2 are distinct if here is some i, for which ith character in s1 and s2 are different.\r\n\r\nNote -> String contains only lowercase letters.\r\n -> The answer will be in the integer range only.","inputFormat":"A String","outputFormat":"An Integer","constraints":"1 &lt;= length of string &lt;= 10000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(String str) {\r\n\t\t// write your code here\r\n\t\t\r\n\t\treturn 0;\r\n\t}\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString str = scn.next();\r\n\t\tSystem.out.println(solution(str));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"bccb","sampleOutput":"6\r\n","questionVideo":"https://www.youtube.com/embed/fvYlinirmFg?end=97","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"575abc6f-ead5-4fce-86c3-24826248e822","name":"Count Of Distinct Palindromic Subsequences ","slug":"count-of-distinct-palindromic-subsequences","type":1}],"next":{"id":"8a1c09a9-5364-4779-8263-e960f54f7be7","name":"Count of distinct palindromic subsequences MCQ","type":0,"slug":"count-of-distinct-palindromic-subsequences-mcq"},"prev":{"id":"a6681732-1f58-4852-8344-ed9189e274d5","name":"Count Distinct Subsequences","type":3,"slug":"count-distinct-subsequences"}}}`

Editor

# Count Of Distinct Palindromic Subsequences

medium

1. You are given a string. 2. You have to print the count of distinct and non-empty palindromic subsequences in the given string. 3. Two sequences s1 and s2 are distinct if here is some i, for which ith character in s1 and s2 are different. Note -> String contains only lowercase letters. -> The answer will be in the integer range only.

## Constraints

1 <= length of string <= 10000

A String

An Integer

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}bccb`

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}6 ```

Question Video

Discussions

Show Discussion

Related Resources