Max Min Discussions | | HackerRank

Max Min

  • + 0 comments

    My rust solution:

    fn maxMin(k: i32, arr: &mut [i32]) -> i32 {
        arr.sort();
        
        arr.windows(k as usize)
            .map(|window| window[(k as usize) -1] - window[0])
            .min()
            .unwrap()