Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int mx = 0;
for(int i = 0; i < s.length(); ++i) {
for(int j = 1; j <= s.length(); ++j) {
string tmp = s.substr(i, j), rev = tmp;
reverse(rev.begin(), rev.end());
if(tmp != rev)
mx = max(mx, int(tmp.length()));
}
}
cout << mx << endl;
return 0;
}
Copy The Code &
Try With Live Editor
Input
mew
Output
3
Demonstration
Codeforces Solution-A. Antipalindrome-Solution in C, C++, Java, Python