Back to course home
0% completed
Vote For New Content
Unique Length-3 Palindromic Subsequences (medium)
Problem Statement
Given a string s
, return the total number of unique palindromes
of length 3
which are subsequences
of s. Even if multiple ways exist to obtain the same subsequence
, it is still only counted once
.
A palindrome
string is a sequence of characters that reads
the same
backward
as forward
.
A subsequence
is a sequence that can be derived from another sequence by deleting
some or no elements without changing
the order
of the remaining elements.
Examples
Example 1:
- Input: s = "abcba"
- Expected Output: 3
- Justification: The three unique length-3 palindromic subsequences are "aba", "aca", and "bcb".
Example 2:
- Input: s = "aba"
- Expected Output: 1
- Justification: The one unique length-3 palindromic subsequence is "aba".
Example 3:
- Input: s = "aacbbcacb"
- Expected Output: 9
- Justification: The nine unique length-3 palindromic subsequences are "aaa", "aca", "aba", "ccc", "cbc", "bbb", "bab", "cac", and "bcb".
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself