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
Press Submit to check your solution.
Back to lesson: Practice: Lock & CAS drills