diff --git a/medium/day_8/solution.cpp b/medium/day_8/solution.cpp index 669069f..0961f4c 100644 --- a/medium/day_8/solution.cpp +++ b/medium/day_8/solution.cpp @@ -1,4 +1,4 @@ -//Write your code here +// Write your code here #include using namespace std; string getsequence(string str, int idx1, int idx2) // this function returns the repeating sequence of string starting with str[i] @@ -23,31 +23,37 @@ int main() string str; string AnsStr; cin >> str; // input the string - if(str.length() == 1) + if (str.length() == 1) { - cout<<-1< MaxLength) //if length of current repeating sequence is greater than previously stored length - { // then update max length - AnsStr=temp;//store max repeating sequence in AnsStr - MaxLength=len; + j = str.find(str[i], j + 1); + if (j == -1) + break; // if there is no more occurence of str[i] is left then we break the loop + string temp = getsequence(str, i, j); // get the sequence of string which is repeating + int len = temp.length(); + if (len > MaxLength) // if length of current repeating sequence is greater than previously stored length + { // then update max length + AnsStr = temp; // store max repeating sequence in AnsStr + MaxLength = len; } } i++; } - - cout<