forked from CodeChef-SMVDU/Solve-It
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepetitions.cpp
More file actions
36 lines (27 loc) · 833 Bytes
/
Copy pathRepetitions.cpp
File metadata and controls
36 lines (27 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*Your task is to find the longest repetition in the sequence.
This is a maximum-length substring containing only one type of character.*/
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
string inputString; //Input String
cin >> inputString;
//2 pointers are used to mark starting and ending of longest substrings containing only one type of character.
int ptr1=0;
int ptr2=0;
int maxLength=0;
int currentLength; // This will store maximum length of each substring with only one type of character
while(ptr1<inputString.length()){
ptr2=ptr1;
currentLength=0;
while(inputString[ptr1]==inputString[ptr2]){
ptr2++;
currentLength++;
if(ptr2>=inputString.length())break;
}
maxLength=max(maxLength,currentLength);
ptr1=ptr2;
}
cout << maxLength << endl;
return 0;
}