Help me in solving LCH15JAB problem

My issue

I can’t understand where the problem is in my solution. I counted the maximum frequency of any character and checked if its equal to half of the string length or not. Should give me the correct answer why isnt it???

My code

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
// Remember *max_element(c,c+n)

#define shit int t;cin>>t;while(t--)
#define pi 3.141597653
#define o 0
#define l 1
#define el endl
#define loop(j,a,b) for(int j=a; j<b; j++)
#define inn int n;cin>>n
#define sinn string s;cin>>s

int main(){
    int t;
    cin>>t;
    while(t--){
        string s; cin>>s;
        sort(s.begin(),s.end());
        int c=1,mx=0;
        loop(i,1,s.length()){
            if(s[i-1]==s[i]){
                c++;
                mx= max(mx,c);
            }
            else{
                c=1;
            }
        }
        if(2*mx == s.length()){
            cout<<"YES"<<el;
        }
        else{
            cout<<"NO"<<el;
        }
    
        
    }
    
    
    
    
    
    
}


Problem Link: LCH15JAB Problem - CodeChef

@umang03r
Your code will fail for test case “ab”
it should be yes your code will print no.

1 Like