Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 947 Bytes

26.md

File metadata and controls

37 lines (29 loc) · 947 Bytes
vector<string> winner(string arr[],int n)
    {
        unordered_map<string,int>m;
        
        for(int i=0;i<n;i++)
        {
          
                 m[arr[i]]++;
        }
        
        vector<string> ans(2);
        int tm=-1;
        
        for(auto it:m)
        {
            if(it.second>tm)
            {
               ans[0]=it.first;
               ans[1] = to_string(it.second); // Convert frequency to string
               tm = it.second;
            }
            
            else if(it.second==tm && it.first<ans[0])
            {
                ans[0]=it.first;
               ans[1] = to_string(it.second); // Convert frequency to string
               tm = it.second;
            }
        }
        
        return ans;
        
    }