Source Code
#include <bits/stdc++.h>

using namespace std;

int main() {
     int n;
    cin>>n;
    string s;
    cin>>s;
    if(s[0] == s[n-1])
        cout<<n-1;
    else
        cout<<n-2;
	return 0;
}
Copy
Pop Pop Mohamedmaher
GNU G++17
9 ms
1.2 MB
Accepted