fn insert_hyphens_reverse(s: &str, interval: usize) -> String {
let mut result = String::new();
let chars: Vec<char> = s.chars().collect();
let mut count = 0;
for &c in chars.iter().rev() {
if count > 0 && count % interval == 0 {
result.push('-');
}
result.push(c);
count += 1;
}
result.chars().rev().collect()
}
// Examples
fn main() {
let input = "1234567890";
let interval = 3;
let result = insert_hyphens_reverse(input, interval);
println!("Original: {}", input);
println!("Modified: {}", result);
let input2 = "abcdefghijklm";
let interval2 = 4;
let result2 = insert_hyphens_reverse(input2, interval2);
println!("Original: {}", input2);
println!("Modified: {}", result2);
}