Problem Brief
Count Special Substrings in a DNA Sequence
NEW GRADOA
You are given a DNA sequence string genome, consisting of lowercase Latin letters.
A substring of genome is considered special if it satisfies one of the following conditions:
Function Signature
def countSpecialSubstrings(genome: str) -> int:
Input
• A single string genome of length n where:
- 1 ≤ n ≤ 3 * 10^5
- genome contains only lowercase letters ('a' to 'z')
Output
• Return the total count of special substrings in the given genome string.
1Example 1
Input
genome = "aabbaa"
Output
4
Explanation
Special substrings: "aa", "bb", "abba", "abba"
Total: 4
2Example 2
Input
genome = "pq"
Output
0
Explanation
No special substrings are present.
3Example 3
Input
genome = "xyyx"
Output
2
Explanation
Special substrings: "yy" (Type 1), "xyyx" (Type 2)
Constraints
Limits and guarantees your solution can rely on.
• 1 ≤ |genome| ≤ 300,000