Counting Sort 1

  • + 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 counting_sort(arr: &[i32]) -> Vec<i32> {
        //Time complexity: O(n+k) or just O(n), since k is constant
        //Space complexity (ignoring input): O(k) or just O(1), since k is constant
        let mut frequency_arr = vec![0; 100];
        for &number in arr{
            frequency_arr[number as usize] += 1;
        }
    
        frequency_arr
    }