Loading RustViz Engine...
Compress characters array in place with run-length encoding (e.g. [a,a,b] -> [a,2,b]).
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 compress(chars: &mut Vec<char>) -> usize {
let mut write = 0;
let mut i = 0;
while i < chars.len() {
let c = chars[i];
let mut count = 0;
while i < chars.len() && chars[i] == c {
i += 1;
count += 1;
}
chars[write] = c;
write += 1;
if count > 1 {
for digit in count.to_string().chars() {
chars[write] = digit;
write += 1;
}
}
}
chars.truncate(write);
write
}