Trains the technique from
LeetCode 1930Unique Length-3 Palindromic SubsequencesThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A tape reads s, a string of lowercase letters. A pick takes three letters from it, keeping their order, and the pick is mirrored when its first and last letters are the same.
Return how many different mirrored picks the tape holds, counting two picks as the same when they read the same.
Example 1
Every one of a, b and c appears at least twice, and the distinct letters lying between the first and last place of each supply the middles, which comes to this many different picks.
Example 2
No letter appears twice, so no pick can have matching ends.
Example 3
The only pick is "aaa".
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def count_palindromic_subsequence(s: str) -> int:public int countPalindromicSubsequence(String s)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.