Life · 1 / 4

First-letter statistics

Collections and grouping

Mediumkotlincollections

Count words by their lower-case first letter. Input strings are either empty or contain only ASCII letters A–Z/a–z. Ignore empty strings and return a Map whose keys iterate in ascending order.

This is a Kotlin/JVM exercise: the reference uses the JVM toSortedMap API. The alphabet restriction is intentional; Char ordering is not linguistic ordering of arbitrary Unicode text.

Check:

  • The provided main example → {a=2, c=1, k=2}.
  • An empty list or only empty strings → an empty Map.
  • listOf("Zoo", "apple", "APPLE", "") → {a=2, z=1}.
  • Count each word once; the rest of its spelling does not affect its group.
Your code
Solution