• + 0 comments

    RUST:

    fn biggerIsGreater(w: &str) -> String {
        let length = w.len();
        let mut temp = w.chars().collect::<Vec<char>>();
        let mut i = None; //
        let mut idx: Option<usize> = None;
        let mut smallest = 'z';
    
        for a in (0..length - 1).rev() {
            if temp[a] < temp[a + 1] {
                i = Some(a);
                break;
        }
    }
        if let Some(i) = i {
        let mut j = i + 1;
        for k in i + 1..length {
        if temp[k] > temp[i] && (j == i + 1 || temp[k] < temp[j]) {
            idx = Some(k);
        }
    }
            if let Some(j) = idx {
                temp.swap(i, j);
                temp[i + 1..].sort();
            }
            temp.iter().collect()
        } else {
            "no answer".into()
        }
    }