Objects as maps

Given a sentence, count how many times each word appears. Print each word and its count, one per line, sorted alphabetically.

Input:  the cat sat on the mat the cat
Output:
cat 2
mat 1
on 1
sat 1
the 3

Constraints

  • Case insensitive: "The" and "the" count as the same word.
  • Output sorted alphabetically by word.
  • Format: word count per line.
Ad SpaceGoogle AdSense active for guests & free-tier learners.