Given a string word, return a dictionary that maps each letter of word to the number of times it appears in word.
Every letter of word is a key, and its value is how many times that letter appears. The order of the entries doesn't matter.
Example 1:
Input: word = "banana"
Output: {"b": 1, "a": 3, "n": 2}
Explanation: "b" appears once, "a" three times and "n" twice.
Example 2:
Input: word = "hello"
Output: {"h": 1, "e": 1, "l": 2, "o": 1}
Explanation: "l" appears twice; every other letter appears once.
Example 3:
Input: word = "a"
Output: {"a": 1}
Explanation: A single letter appears once.
Constraints:
wordhas at least one letter.wordis made of lowercase English letters,atoz.- Only the letters of
wordare keys: a letter that doesn't appear has no entry.
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
