Skip to content

Commit

Permalink
feat: soltuion added for mediumday8
Browse files Browse the repository at this point in the history
  • Loading branch information
deepanshpandey108 committed Apr 10, 2024
1 parent e02c621 commit 682a94a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion medium/day_8/solution.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
//Write your code here
//Write your code here
#include <iostream>
#include <string>

using namespace std;

string func(const string& s) {
int n = s.length();
int max_length = 0;
int max_index = -1;

for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int length = 0;
while (j + length < n && s[i + length] == s[j + length]) {
++length;
}
if (length > max_length) {
max_length = length;
max_index = i;
}
}
}

if (max_length == 0) {
return "-1";
} else {
return s.substr(max_index, max_length);
}
}

int main() {
string s;
cin>>s;

string result = func(s);
cout << result << endl;

return 0;
}

Binary file added medium/day_8/solution.exe
Binary file not shown.

0 comments on commit 682a94a

Please sign in to comment.