Count Character Occurrences

Given a string s consisting of lowercase English letters, count how many times each character appears and return the result as a space-separated list of…

Given a string `s` consisting of lowercase English letters, count how many times each character appears and return the result as a space-separated list of `char:count` pairs ordered by the first appearance of each character in `s`. For example, given `s = "aabbbc"`, the character `'a'` appears 2 times, `'b'` appears 3 times, and `'c'` appears 1 time, so the output is `"a:2 b:3 c:1"`.

- `1 <= s.length <= 10^5` - `s` consists only of lowercase English letters (`a`–`z`). - The interactive visualizer accepts `1 <= s.length <= 20`; longer valid judge inputs are execution-only. - Output pairs must be ordered by each character's first appearance in `s`. - Each pair is formatted as `char:count` with pairs separated by a single space.

Example 1: input s = "mnnoopq"; output "m:1 n:2 o:2 p:1 q:1". Scanning left to right — m appears 1 time, n appears 2 times, o appears 2 times, p appears 1 time, q appears 1 time. Pairs are emitted in first-appearance order.

Example 2: input s = "rsstttu"; output "r:1 s:2 t:3 u:1". r is seen once, s twice, t three times, and u once. Output follows first-appearance order.

Example 3: input s = "pppp"; output "p:4". Only one distinct character appears. Its count equals the full length of the string.

Category: Strings. Topic: strings. Difficulty: Easy. Patterns: hashing.