Character Frequency in Alphabetical Order
EasyP3Coding
Given a string s of lower-case letters, return one entry per distinct character, in alphabetical order. Each entry has the form "<char>-<count>", where count is the number of times the character occurs in s.
For an empty string return an empty array.
Example 1
- Input
- s = "banana"
- Output
- ["a-3","b-1","n-2"]
- Why
- a occurs 3 times, b once, n twice.
Example 2
- Input
- s = "aabbbc"
- Output
- ["a-2","b-3","c-1"]
Example 3
- Input
- s = ""
- Output
- []
Constraints
- 0 <= s.length <= 10^5
- s contains only lower-case letters a-z
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.