You are given a string S consisting of lowercase English letters.
Count the total number of palindromic subsequences of length exactly 3.
A subsequence is obtained by deleting zero or more characters without changing the order of the remaining characters.
A palindrome reads the same forwards and backwards.
Print the total count.
Print a single integer representing the number of palindromic subsequences of length 3.
abca
2
The valid palindromic subsequences are:
abaacaaaa
1
aaaa
4
Choose any 3 of the 4 'a' characters:
[ \binom{4}{3}=4 ]
Hence the answer is 4.
Texas • Pending