Given a string str of length N, you have to find number of palindromic subsequence (need not necessarily be distinct) which could be formed from the string str.
Input: Str = "abcd" Output: 4 Explanation: palindromic subsequence are : "a" ,"b", "c" ,"d"
Input: Str = "aab" Output: 4 Explanation: palindromic subsequence are :"a", "a", "b", "aa"
You don't need to read input or print anything. Your task is to complete the function countPs() which takes a string str as input parameter and returns the number of palindromic subsequence.
Expected Time Complexity: O(N*N)
Expected Auxiliary Space: O(N*N)
1<=length of string str <=30
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes