## Friday, November 11, 2016

### Check if a string has all characters with same frequency with one variation allowed - GeeksforGeeks

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
1. int main() {
2. string str;
3. cin>>str;
4. int T[26]={0};
5. for(int i=0;i<str.length();i++)
6. T[str[i]-'a']++;
7. int ans=0,res;
8. for(int i=0;i<26;i++)
9. {
10. if(T[i]!=0)
11. {
12. res=T[i];
13. break;
14. }
15. }
16. //cout<<"i ki val "<<res<<endl;
17. for(int i=0;i<26;i++)
18. if(T[i]!=res && T[i]!=0)
19. ans++;
20. //cout<<ans<<" "<<endl;
21. if(ans==1 ||ans==0)
22. cout<<"Yes\n";
23. else cout<<"No\n";
24.
25. return 0;
26. }
Read full article from Check if a string has all characters with same frequency with one variation allowed - GeeksforGeeks