Skip to content
Onsite

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

Run checks the 3 visible tests, Submit all 10.