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-2<<endl;
    else cout<<n-1<<endl;
}
Copy
Pop Pop sharlok not active_74
GNU G++17
4 ms
472 KB
Accepted