BackmediumStrings PayPal

Analyzing Genome Sequences Solution

Problem Statement

Given a DNA sequence consisting of the four nucleotide bases (A, C, G, T), count the number of substrings where no two consecutive characters represent the same nucleotide base.

Example 1
Input
ATCG
Output
5

Explanation: Step-by-step: with input ATCG, we split it into 'A', 'T', 'C', 'G', 'AT', 'TC', but exclude 'AT' and 'TC' because they have consecutive repeating nucleotide bases. So the correct count is 5.

Example 2
Input
AAAA
Output
4

Explanation: Step-by-step: with input AAAA, we split it into 'A', 'A', 'A', 'A', but exclude 'AA' because it has consecutive repeating nucleotide bases. So the correct count is 4.

Constraints

  • 1 <= length of DNA sequence <= 1000
  • DNA sequence only contains the characters 'A', 'C', 'G', 'T'
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free