You have a chat log of n messages. You are given two string arrays messages and senders where messages[i] is a message sent by senders[i].

A message is list of words that are separated by a single space with no leading or trailing spaces. The word count of a sender is the total number of words sent by the sender. Note that a sender may send more than one message.

Return the sender with the largest word count. If there is more than one sender with the largest word count, return the one with the lexicographically largest name.

Note:


	Uppercase letters come before lowercase letters in lexicographical order.
	"Alice" and "alice" are distinct.


&nbsp;
Example 1:

Input: messages = ["Hello userTwooo","Hi userThree","Wonderful day Alice","Nice day userThree"], senders = ["Alice","userTwo","userThree","Alice"]
Output: "Alice"
Explanation: Alice sends a total of 2 + 3 = 5 words.
userTwo sends a total of 2 words.
userThree sends a total of 3 words.
Since Alice has the largest word count, we return "Alice".


Example 2:

Input: messages = ["How is leetcode for everyone","Leetcode is useful for practice"], senders = ["Bob","Charlie"]
Output: "Charlie"
Explanation: Bob sends a total of 5 words.
Charlie sends a total of 5 words.
Since there is a tie for the largest word count, we return the sender with the lexicographically larger name, Charlie.

&nbsp;
Constraints:


	n == messages.length == senders.length
	1 &lt;= n &lt;= 104
	1 &lt;= messages[i].length &lt;= 100
	1 &lt;= senders[i].length &lt;= 10
	messages[i] consists of uppercase and lowercase English letters and ' '.
	All the words in messages[i] are separated by a single space.
	messages[i] does not have leading or trailing spaces.
	senders[i] consists of uppercase and lowercase English letters only.


class Solution:
    def largestWordCount(self, messages: List[str], senders: List[str]) -> str:
        d={}
        l=[]
        for i in range(len(messages)):
            if senders[i] not in d:
                d[senders[i]]=len(messages[i].split())
            else:
                d[senders[i]]+=len(messages[i].split())
        x=max(d.values())
        for k,v in d.items():
            if v==x :
                l.append(k)
        if len(l)==1:
            return l[0]
        else:
            l=sorted(l)[::-1]      #Lexigograhical sorting of list
            return l[0]
class Solution {
    public String largestWordCount(String[] messages, String[] senders) {
        HashMap<String,Integer> hm=new HashMap<>();
		
        int max=0;
        String name="";
        for(int i=0;i<messages.length;i++){
            String[] words=messages[i].split(" ");
            
            int freq=hm.getOrDefault(senders[i],0)+words.length;
            hm.put(senders[i],freq);
            
            if(hm.get(senders[i])>max){
                max=hm.get(senders[i]);
                name=senders[i];
            }
            else if(hm.get(senders[i])==max && name.compareTo(senders[i])<0){
                name=senders[i];
            } 
        }
        
        return name;
    }
}
class Solution {
public:
    string largestWordCount(vector<string>& messages, vector<string>& senders) {

        int n(size(messages));
        map<string, int> m;
        for (auto i=0; i<n; i++) {

            stringstream ss(messages[i]);
            string word;
            int count(0);
            while (ss >> word) count++;
            m[senders[i]] += count;
        }

        int count(0);
        string res;
        for (auto& p : m) {
            if (p.second >= count) {
                count = p.second;
                if (!res.empty() or res < p.first) res = p.first;
            }
        }
        return res;
    }
};
/**
 * @param {string[]} messages
 * @param {string[]} senders
 * @return {string}
 */
var largestWordCount = function(messages, senders) {
    let wordCount = {}
    let result = ''
    let maxCount = -Infinity
    for (let i = 0; i < messages.length;i++) {
        let count=messages[i].split(' ').length
        wordCount[senders[i]] = wordCount[senders[i]] == undefined ? count : wordCount[senders[i]] + count;
        if (wordCount[senders[i]]  > maxCount || (wordCount[senders[i]]  == maxCount && senders[i] > result)) {
            maxCount = wordCount[senders[i]];
            result = senders[i];
        }
    }
    return result;

};
Sender With Largest Word Count