From 7b01bde329d83fdfba356886c6ed570576d09c4a Mon Sep 17 00:00:00 2001 From: AKS Date: Fri, 5 Apr 2024 15:46:29 +0530 Subject: [PATCH] updated solution to day 8 medium --- medium/day_8/solution.cpp | 42 ++++++++++++++++++++++---------------- medium/day_8/solution.exe | Bin 52863 -> 53428 bytes 2 files changed, 24 insertions(+), 18 deletions(-) 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<t_rYH1T7&#`tlgHy1Z#cdn3J+!*6V*S^1+X{M*Le`dG* zoIYLOI#qSfsp{%xl=ga^X!WwyE!*&^b{*M9NWTanK7zj>Mv&=*kmV4@LZEdJ6NDID z_uwkj1PIg45{()v%R+?4YY(YygqZ#5cCQq*s-2MV#+XobXCwO4=Nd;hCaGxRPK{qc z5<2Q2)9I^1>@*YZFff@7@hC=;WS>%ARA4S3q|*xx`4Bd1GW}AB@-4$%03?-qi%~*V zW6UU;DhB)7WSm2D#VEQ@97k>YDTA+>)exTdbeuT7YOh!_#GB`FP z>5ezOK@3$!QfoJ7SjW$7GLnM<%pl94vS#X--O)tZ#Kn>rd!1({#;U;_hj6imIY-br zZfP;?z_7!z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