Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
if(s1.size() != s2.size())
cout << max(s1.size(), s2.size()) << endl;
else if(s1 == s2)
cout << -1 << endl;
else
cout << s1.size() << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
abcd
defgh
defgh
Output
5
Demonstration
Codeforces Solution-Mahmoud and Longest Uncommon Subsequence-Solution in C, C++, Java, Python