Check if a string has all characters with same frequency with one variation allowed - GeeksforGeeks
Given a string of lowercase alphabets, find if it can be converted to a Valid String by removing 1 or 0 characters. A "valid" string is a string str such that for all distinct characters in str each such character occurs the same number of times in it.
http://ideone.com/m3ILm6
Given a string of lowercase alphabets, find if it can be converted to a Valid String by removing 1 or 0 characters. A "valid" string is a string str such that for all distinct characters in str each such character occurs the same number of times in it.
http://ideone.com/m3ILm6
- int main() {
- string str;
- cin>>str;
- int T[26]={0};
- for(int i=0;i<str.length();i++)
- T[str[i]-'a']++;
- int ans=0,res;
- for(int i=0;i<26;i++)
- {
- if(T[i]!=0)
- {
- res=T[i];
- break;
- }
- }
- //cout<<"i ki val "<<res<<endl;
- for(int i=0;i<26;i++)
- if(T[i]!=res && T[i]!=0)
- ans++;
- //cout<<ans<<" "<<endl;
- if(ans==1 ||ans==0)
- cout<<"Yes\n";
- else cout<<"No\n";
- return 0;
- }