Rust solution 4ms
\n    pub fn minimum_incompatibility(nums: Vec<i32>, k: i32) -> i32 {\n        fn dfs(ind: usize, nums: &Vec<i32>, buckets: &mut Vec<VecDeque<i32>>, k: usize, b
```\n    pub fn minimum_incompatibility(nums: Vec<i32>, k: i32) -> i32 {\n        fn dfs(ind: usize, nums: &Vec<i32>, buckets: &mut Vec<VecDeque<i32>>, k: usize, bucket_len: usize, total: i32, res: &mut i32) {\n            if ind == nums.len() {\n                *res = total;\n                return;\n            }\n            \n            for i in 0..buckets.len().min(k + 1) {\n                if buckets[i].len() < bucket_len &&\n                    (buckets[i].is_empty() || *buckets[i].back().unwrap() < nums[ind])\n                 {\n                    let cur = nums[ind] - *buckets[i].back().unwrap_or(&nums[ind]) + total;\n                    if cur < *res {\n                        buckets[i].push_back(nums[ind]);\n                        dfs(ind + 1, nums, buckets, k.max(i + 1), bucket_len, cur, res);\n                        buckets[i].pop_back();\n                    }\n                }\n            }\n        }\n\n        let mut nums = nums;\n        nums.sort();\n        let k = k as usize;\n        let mut buckets = vec![VecDeque::with_capacity(nums.len() / k as usize); k as usize];\n        let mut res = std::i32::MAX;\n        dfs(0, &nums, &mut buckets, 0, nums.len() / k as usize, 0, &mut res);\n        if res == std::i32::MAX {\n            return -1;\n        }\n        res\n    }\n```
['Backtracking', 'Rust']