#K12436. Longest Alternating DNA Subsequence
Longest Alternating DNA Subsequence
Longest Alternating DNA Subsequence
You are given a DNA sequence of length \(n\) consisting of the nucleotides 'A', 'C', 'G', and 'T'. Your task is to determine the length of the longest contiguous subsequence that alternates between two different nucleotides. In other words, every two consecutive characters in this subsequence must be different.
Note: If the input sequence has a length less than 2, then the answer is 0 because at least two characters are needed for alternation.
Example: For a sequence ACGTACGT
of length 8, the entire string is alternating, so the answer is 8.
inputFormat
The input is read from stdin and consists of two lines:
- An integer \(n\) representing the length of the DNA sequence.
- A string of \(n\) characters where each character is one of 'A', 'C', 'G', or 'T'.
outputFormat
Output a single integer to stdout representing the length of the longest contiguous subsequence of the DNA sequence that alternates strictly between two different nucleotides.
## sample8
ACGTACGT
8
</p>