Loading RustViz Engine...
Group list of strings into anagram clusters using byte frequency arrays as keys.
This problem is currently in blueprint template mode. Once the concept foundation is finalized, live in-browser WebAssembly compilation and test assertion runners will be enabled here.
use std::collections::HashMap;
pub fn group_anagrams(strs: Vec<String>) -> Vec<Vec<String>> {
let mut map: HashMap<[u8; 26], Vec<String>> = HashMap::new();
for s in strs {
let mut key = [0u8; 26];
for b in s.bytes() {
key[(b - b'a') as usize] += 1;
}
map.entry(key).or_default().push(s);
}
map.into_values().collect()
}