Skip to content
Onsite

Count Name Frequencies

EasyP3Coding

Given a list of names, return one entry per distinct name, in ascending alphabetical order (plain string comparison, so upper-case letters sort before lower-case). Each entry has the form "<name> <count>" with a single space, where count is how many times the name appears.

Example 1

Input
names = ["bob","alice","bob"]
Output
["alice 1","bob 2"]
Why
bob appears twice, alice once.

Example 2

Input
names = ["x"]
Output
["x 1"]

Example 3

Input
names = []
Output
[]

Constraints

  • 0 <= names.length <= 10^5
  • Each name is a non-empty string without spaces

Hints

Run checks the 3 visible tests, Submit all 10.