Is Special Sequence
Learn this problemProblem statement
Data scientists at Amazon are working on a utility for genome sequencing algorithms that look for palindromic patterns in DNA sequence strings.
A DNA sequence string is considered special if it can be divided into two non-empty substrings such that the resulting strings can be rearranged to form palindromes after removing at most one character from each of them.
Given a string, dna_sequence, return the string "YES" if it is a special sequence and "NO" otherwise.
Note: A substring is defined as any contiguous segment of a string. A palindrome is a string that reads the same forwards and backwards such as "abccba", "aba", "b", and "ccc".
Function
isSpecialSequence(dna_sequence: String) → String
Complete the function isSpecialSequence in the editor below.
isSpecialSequence takes the following arguments:
str dna_sequence: the given string of dna sequence
Returns
string: "YES" if the given sequence is special and "NO" otherwise
Examples
Example 1
dna_sequence = "abcad"return = "YES"
Constraints
- 1 ≤ length(
dna_sequence) ≤ 3 * 10^5 - It is guaranteed that the sequence consists of lowercase English characters only.
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