Post

Repeatations

Problem Source

Problem Statement

You are given a DNA sequence: a string consisting of characters A, C, G, and T. Your task is to find the longest repetition in the sequence. This is a maximum-length substring containing only one type of character.

Solution

1
2
3
4
5
6
7
8
9
10
11
12
s = input()
 
current = 1
result = 1
pre = '?'
 
for c in s:
    current = current + 1 if c == pre else 1
    result = max(result, current)
    pre = c
 
print(result)
This post is licensed under CC BY 4.0 by the author.