Loading RustViz Engine...
Scan ASCII string and return first unique character index using array frequency table.
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.
pub fn first_uniq_char(s: &str) -> Option<usize> {
let mut counts = [0u16; 26];
for b in s.bytes() {
if b.is_ascii_lowercase() {
counts[(b - b'a') as usize] += 1;
}
}
for (i, b) in s.bytes().enumerate() {
if b.is_ascii_lowercase() && counts[(b - b'a') as usize] == 1 {
return Some(i);
}
}
None
}