JavaMediumHashing20 min
List duplicate characters with frequencies
Print duplicated characters in first-appearance order, each as character:count on its own line. Print NONE if none repeat. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe boundary handling and collection selection.
Input
One line of lowercase English letters, possibly empty.
Output
Print duplicated characters in first-appearance order, each as character:count on its own line. Print NONE if none repeat.
Constraints
0 <= length <= 100000.
Example
Input
programming
Output
r:2 g:2 m:2
Example 2 input
zzzzaabbz
Output
z:5 a:2 b:2
This example exercises a further boundary or ordering case.
Public test cases (2)
Input
programming
Expected output
r:2 g:2 m:2
Input
banana
Expected output
a:3 n:2
Hints (2)
- Identify the state needed to avoid recomputing work for each element.
- Use a LinkedHashMap so frequency counting also preserves first appearance.
Target complexity: time O(n) · space O(1), fixed alphabet
