Find the word that occurs with the highest frequency in a space-separated string, breaking ties by returning the first occurring word.
Problem Statement
Examples
Input: s = "apple banana apple orange banana apple"
Output: "apple"
Explanation: 'apple' appears 3 times.
Input: s = "cat dog cat dog parrot"
Output: "cat"
Explanation: Both 'cat' and 'dog' appear 2 times. 'cat' appears first in the string.
Input: s = "code assist consist code consist code"
Output: "code"
Explanation: 'code' appears 3 times.
Constraints
1 <= s.length <= 10^5 s consists of lowercase English letters and single spaces Words are separated by exactly one space with no leading or trailing spaces
Complexity
Time Complexity: O(N)
Space Complexity: O(W)