Alphabetic String.....

 Program of Alphabetic String in codeforces..........


void solve(){


string s; 

cin>>5;

 deque<char>dq

 char maxi='a';

 for(int i=0;i<(int)s.size(); i++)

{

maxi=max(maxi,s[i]);

 dq.push_back(s[i]);

}

for(char ch = maxi;ch>='a';ch--) 

{

 if(dq.size()==0)

{

cout<<"NO"<<"\n";

 Return;

}

if (dq. front() == ch) dq pop_front(); 

else if(dq.back() == ch) dq.pop_back();

else{

cout<<"NO"<<"\n";

 Return;

}

}

if(dq.size()==0) 

cout<<"YES"<<"\n";

 else 

cout<<"NO"<<"\n";

}


Comments

Popular posts from this blog

About RAM

Class and object in c++