s to the number of times it appears.Character Counts
L2 Easy Strings
Concept
Dictionaries do not have to use integers as keys — characters work just as well for letter-count problems.
Return a dictionary mapping each character of
Examples
▸ s = "aab"
→ {"a": 2, "b": 1}
▸ s = ""
→ {}
▸ s = "zz"
→ {"z": 2}
Progressive Hints
Hint 1 · Nudge
A dictionary's keys don't have to be numbers, characters work just the same.
Hint 2 · Plan
Create an empty map. Walk the string and add 1 to each character's tally, starting new letters at 0. Return the filled map.
Hint 3 · Approach
counts = empty map. For each c in s: counts[c] = counts.getOrDefault(c, 0) + 1. Return counts.
All hints are out. Take a breath and give it a shot.
Output
// Run your code to see the output here.