Skip to main content

Practice ยท 2 of 3

The compute family

Implement with ConcurrentHashMap ONLY (no explicit synchronized blocks): 1. static Map<String,Integer> frequency(List<String> words) โ€” count occurrences using merge. 2. static Map<String,List<String>> indexByFirstLetter(List<String> words) โ€” group using computeIfAbsent, appending into the existing list on repeat letters. 3. static int uniqueId(Map<String,Integer> registry, String name) โ€” reserve name with computeIfAbsent assigning registry.size(); a repeat call with the same name must return the SAME id (never two ids for one name).

Difficulty: advanced

Back to lesson: Practice: Lock & CAS drills