Left Rotation

  • + 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

    fn left_rotation(d: i32, arr: &[i32]) -> Vec<i32> {
        //Time complexity: O(n)
        //Space complexity (ignoring input): O(n)
        let mut new_array = Vec::new();
        for index in 0..arr.len() {
            new_array.push(arr[(index + d as usize) % arr.len()]);
        }
    
        new_array
    }