Problem · String
Count Special Substrings in a DNA Sequence
Learn this problemProblem statement
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.
Function
countSpecialSubstrings(genome: String) → intExamples
Example 1
genome = "aabbaa"return = 4Special substrings: "aa", "bb", "abba", "abba"
Total: 4
Example 2
genome = "pq"return = 0No special substrings are present.
Example 3
genome = "xyyx"return = 2Special substrings: "yy" (Type 1), "xyyx" (Type 2)
Constraints
• 1 ≤ |genome| ≤ 300,000
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026