Mars Exploration

  • + 0 comments

    Rust best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    pub fn mars_exploration(s: &str) -> i32 {
        //Time complexity: O(n)
        //Space complexity (ignoring input): O(1)
        let sos_array: Vec<_> = "SOS".chars().collect();
        let mut changed_letters = 0;
        for (index, letter) in s.char_indices(){
            if letter != sos_array[index%3]{
                changed_letters += 1;
            }
        }
        changed_letters
    }