RECNDSTR - Editorial

for i in range (int(input())):
list = input()
setOfList=set(list)
if len(setOfList)==1 or len(list)==2:
print(‘YES’)

elif len(list)%2==0 and all(list[0] == c for c in list[: : 2]) and all(list[1] == c for c in list[1: : 2]):
    print('YES')

else:
    print('NO')

CodeChef: Practical coding for everyone tried this approach using string slicing :slight_smile: was accepted and was even fast enough…

All we need to do is check if L(S) == R(S), that is, if left shift and right shift of a input string results in the same string.

T = int(input())
for i in range (T):
    S = input()
    L_S = S[1:] + S[0]
    R_S = S[-1] + S[0:-1]
    if L_S == R_S:
        print("YES")
    else: 
        print("NO")
#include<bits/stdc++.h>
using namespace std;
string leftshift(string s){
    int n = s.size();
    char temp = s[0];
    for(int i = 0;i<n-1;i++){
        s[i] = s[i+1];
    }
    s[n-1] = temp;
    return s;
}
string rightshift(string s){
    int n = s.size();
    char temp = s[n-1];
    for(int i = n-1;i>=0;i--)
        s[i] = s[i-1];
    s[0] = temp;
    return s;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        string s1;
        cin>>s1;
        string s2;
        s2 = leftshift(s1);
        bool flag = false;
        if(leftshift(s2) == rightshift(s2))
            flag = true;
        if(flag)
            cout<<"YES\n";
        else 
            cout<<"NO\n";
    }
    return 0;
}

please help me why my solutions is wrong
https://www.codechef.com/viewsolution/64258290

why my solution is wrong???

void solve(){
string s;cin>>s;
set name;
for(auto it: s){
name.insert(it);
}
if(name.size()==1){
cout<<“YES”<<endl;
return;
}
if(name.size()>2){
cout<<“NO”<<endl;
return;
}
if(name.size()==2){
map<char,ll>freq;
for(int i=0; i<s.size(); i++){
freq[s[i]]++;
}

    ll count = 0;
    for(auto it:freq){
        count = it.second;
        if(it.second != count){
            cout<<"NO"<<endl;
            return;
        }
        else {
            cout<<"YES"<<endl;
            return;
        }
    }   
}

}

int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//this is fast I/O (inputput output) use header file <cstdio>
ll t;cin>>t;
while(t--){
    solve();
 
}
return 0;

}

just find the two string can be done in o(1) time complexity

#include
#include
#include
#include
using namespace std;
#define ll long long int
const unsigned int mod = 1e9+7;

int main(){

ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//this is fast I/O (inputput output) use header file <cstdio>
int t;cin>>t;
while(t--){
    string s;cin>>s;
    string a = s.substr(1) + s[0];
    string b = s[s.size()-1]+s.substr(0,s.size()-1);
    //cout<<a<<endl<<b<<endl;
    if(a==b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
return 0;

}

//CODECHEF
//PROBLEMCODE : RECNDSTR

#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin >> t;
    while(t--){
        string a;
        cin >> a;
        if(a.length() == 1){
            cout << "YES" << endl;
        }
        else{
            string sub = "";
            sub = sub + a[0] + a[1];
            int i = 0;
            while(i < a.length()){
                if(sub[i % 2] != a[i]){
                    break;
                }
                i++;
            }
            if(i == a.length()){
                cout << "YES" << endl;
            }
            else{
                cout << "NO" << endl;
            }
        }
    }
    return 0;
}

@
This is my approach to the problem, when the length of string is 1 then we can print YES, otherwise I am going to take the first two characters of the string to make a substring and compare this substring with the remaining string to find whether they are matching (eg :- considering string ababab, search the string whether the pattern is repeating till the end, if yes then print yes else no.

Am I missing any boundary cases, since I can’t find any.