Given a string sentence, count how many times each word appears in it. Return a map where each word of the sentence is a key, and its value is the number of times that word appears.
The words are in lower case and separated by single spaces, and the sentence has at least one word. The order of the entries doesn't matter.
Example 1:
Input: sentence = "the cat and the hat"
Output: {"the": 2, "cat": 1, "and": 1, "hat": 1}
Explanation: "the" appears twice. Every other word appears once.
Example 2:
Input: sentence = "go go go"
Output: {"go": 3}
Explanation: The same word three times gives one key, "go", with the value 3.
Example 3:
Input: sentence = "hello"
Output: {"hello": 1}
Explanation: A sentence of one word: that word appears once.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
