Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Even if a palindrome can be formed in several ways, it is counted once. A subsequence keeps the relative order of characters but may delete some of them.
Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Even if a palindrome can be formed in several ways, it is counted once. A subsequence keeps the relative order of characters but may delete some of them.
Example 1:
Input: {"s":"aabca"}
Output: 3
Constraints:
3≤s.length≤105
s consists of only lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"s":"aabca"}
A length-3 palindrome is x?x. For each outer letter x, use its first and last positions: any letter strictly between them can be the middle.