Search code examples
palindromesubsequence

Print all Palindromic Subsequences in a given string (not distinct)


There are many problems of this kind on GFG like Count All Palindromic Subsequence in a given String. But I have not found this question anywhere:

Print all Palindromic Subsequences in a given string (not distinct).

I looked at this article on GFG and tried to test it for string "aba" for understanding and I found the ans as 5 but according to me, the possible palindromic subsequences are {'a','b','a','aa'} and they are 4.

So my question is why it is 5 and what is the fifth palindromic subsequence in "aba" that I am not able to find? 

Because of this I am not able to understand the question Count All Palindromic Subsequence in a given String. Kindly help!


Solution

  • Since aba is already a palindrome, it must be included in the set of all palindromic subsequences.

    So the final answer would be: {'a','b','a','aa','aba'}.