Repetitions CSES solution

Repetitions CSES solution
Repetitions CSES solution

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.

Input

The only input line contains a string of n characters.

Output

Print one integer: the length of the longest repetition.

Constraints

  • 1≤n≤1061≤n≤106

Example

Input:
ATTCGGGA

Output:
3

Code Solution

//Repetitions CSES solution codesagar.in

import java.util.*;
 
public class Repi {
    
    
    public static void main(String args[]) {
     // Missing Number
    Scanner sc = new Scanner(System.in);
int count=0;
String s=sc.next();
int i=0;
while(i< s.length()-1){
    int cur_count=0;
    
    while(i+1 < s.length() && s.charAt(i)==s.charAt(i+1)){
        cur_count++;
        i++;
    }
    
i++;    
    if(count<cur_count){
        count=cur_count;
    }
}
System.out.println(count+1);
		
    }
}


//Repetitions CSES solution codesagar.in

Leave a Comment