2049B - pspspsps void solve() { ll n; cin >> n; string s; cin >> s; ll cp=0,cs=0;
// Counting p's and s's forn { if(s[i]=='p') cp++; if(s[i]=='s') cs++; } // Now if either p or s is absent....viola if(cp==0 || cs==0) { cout<<"YES"<<endl; return; } // If there is only 1 s and its at the start...I have no problem if(cs==1 && s[0]=='s') { cout<<"YES"<<endl; return; } //Same for p but last index if(cp==1 && s[n-1]=='p') { cout<<"YES"<<endl; return; } /* Lets see if you reach here then 1. definitely there is atleast 1p and 1s 2. solution can be of the form spppp or ssssp with dots 3. if both s and p are greater than 1 then no solution is possible 4. if one of them occurs exactly once then it is not at the right place i.e first for s and last for p 5. therefor there can be a solution no more. */ cout<<"NO"<<endl; return;
}