PalindromicSubsequences
TCO20 North America Qualifier · 2020-09-19 · by erinn
Problem Statement
A palindrome is a sequence that can be read the same forwards and backwards. For example, ABBA and ABCBA are palindromes, while ABCAB and ACAB are not.
Given a
Constraints
- s will contain between 1 and 100 upper-case ('A'-'Z') characters.
"AB" Returns: 2
The best we can do here is to take either single letter as a palindrome.
"ABA" Returns: 5
We can take any single letter, the pair AA, or the whole string ABA, a total of 5 possibilities.
"AAA" Returns: 7
Any non-empty subsequence is a palindrome.
"ABCBA" Returns: 13
"ABCDEFGHABC" Returns: 35
Submissions are judged against all 14 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PalindromicSubsequences with a public method int count(string s) · 14 test cases · 2 s / 256 MB per case