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.
Examples
01 · Example 1
genome = "aabbaa" return = 4
Special substrings: "aa", "bb", "abba", "abba"
Total: 4
02 · Example 2
genome = "pq" return = 0
No special substrings are present.
03 · Example 3
genome = "xyyx" return = 2
Special substrings: "yy" (Type 1), "xyyx" (Type 2)
Constraints
• 1 ≤ |genome| ≤ 300,000
More Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int countSpecialSubstrings(String s) {
// write your code here
}
genome"aabbaa"
expected4
sign in to submit