Skip to content

Practice Unique Length-3 Palindromic Subsequences

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1930
LeetCode Problem

Unique Length-3 Palindromic Subsequences

Problem Statement

Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once. A palindrome is a string that reads the same forwards and backwards. A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.

Source: Unique Length-3 Palindromic Subsequences on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "aabca"
Output
3

# Example 2

Input
s = "adc"
Output
0

# Example 3

Input
s = "bbcbaba"
Output
4

Constraints

3 <= s.length <= 10^5
s consists of only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Unique Length-3 Palindromic Subsequences.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.