FastPrepFastPrep
Problem Brief

Is Special Sequence

FULLTIMEOA

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 Description

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

1Example 1

Input
dna_sequence = "abcad"
Output
"YES"
Explanation
Example 1 illustration
Thus the answer is "YES".

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ length(dna_sequence) ≤ 3 * 10^5
  • It is guaranteed that the sequence consists of lowercase English characters only.
public String isSpecialSequence(String dna_sequence) {
  // write your code here
}
Input

dna_sequence

"abcad"

Output

"YES"

Sign in to submit your solution.