Java, O(N)
Please upvote if helpful.\n\nclass Solution {\n    public String largestWordCount(String[] messages, String[] senders) {\n        // Count the words for every s
Please upvote if helpful.\n```\nclass Solution {\n    public String largestWordCount(String[] messages, String[] senders) {\n        // Count the words for every sender and return the sender with the maximum words.\n        // Time: O(N), Space: O(N)\n        Map<String, Integer> map = new HashMap();\n        String ans = "";\n        for (int i = 0; i < senders.length; i++) {\n            if (!map.containsKey(senders[i])) map.put(senders[i], 0);\n            int max = ans == "" ? 0 : map.get(ans);\n            map.put(senders[i], map.get(senders[i]) + messages[i].split(" ").length);\n            if (map.get(senders[i]) >= max) {\n                if (map.get(senders[i]) == max) {\n                    ans = senders[i].compareTo(ans) < 0 ? ans : senders[i];\n                } else {\n                    ans = senders[i];\n                }\n            }\n        }\n        return ans;\n    }\n}\n```
[]