fn main() { proconio::input! { s: String, } let mut c = s.chars().collect::>(); for i in 0..c.len() { let max = c .iter() .copied() .enumerate() .skip(i) .filter(|&(_, x)| x > c[i]) .max_by_key(|x| x.1); if let Some((j, _)) = max { c.swap(i, j); break; } } println!("{}", c.iter().collect::()); }