beat 100 %  sol
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[]} nums\n * @param {number} k\n * @return {number}\n */\nvar minimumIncompatibility = function(nums, k) {\n    const N = nums.length;\n\n    function bits(x) {\n        let ret = 0;\n        while (x) {\n            ret += (x & 1);\n            x = x >> 1;\n        }\n        return ret;\n    }\n\n    function check(x, nums) {\n        const seen = Array(17).fill(false);\n        for (let i = 0; i < N; i++) {\n            if ((1 << i) & x) {\n                if (seen[nums[i]]) return false;\n                seen[nums[i]] = true;\n            }\n        }\n        return true;\n    }\n\n    function calculate(x, nums) {\n        let Max = 1, Min = 16;\n        for (let i = 0; i < N; i++) {\n            if ((1 << i) & x) {\n                Max = Math.max(Max, nums[i]);\n                Min = Math.min(Min, nums[i]);\n            }\n        }\n        return Max - Min;\n    }\n\n    const dp = new Array(1 << N).fill(Number.MAX_SAFE_INTEGER);\n    const mp = new Map();\n    const requiredSubsetSize = N / k;\n\n    if (requiredSubsetSize === 1) return 0;\n\n    for (let i = 1; i < (1 << N); i++) {\n        const b = bits(i);\n        if ((b % requiredSubsetSize) === 0 && (b !== requiredSubsetSize || check(i, nums))) {\n            if (!mp.has(b)) {\n                mp.set(b, []);\n            }\n            mp.get(b).push(i);\n        }\n    }\n\n \n    const subsetSizeValues = mp.get(requiredSubsetSize);\n    if (!subsetSizeValues || !subsetSizeValues[Symbol.iterator]) {\n        return -1;\n    }\n\n   \n    for (const x of Array.from(subsetSizeValues)) {\n        dp[x] = calculate(x, nums);\n    }\n\n    let cur = requiredSubsetSize;\n    while (cur < N) {\n        const currentValues = mp.get(cur);\n        if (currentValues && currentValues[Symbol.iterator]) {\n            for (const x of Array.from(currentValues)) {\n                if (dp[x] === Number.MAX_SAFE_INTEGER) continue;\n                const subsetSizeValues = mp.get(requiredSubsetSize);\n                if (!subsetSizeValues || !subsetSizeValues[Symbol.iterator]) {\n                    continue; \n                }\n                for (const y of Array.from(subsetSizeValues)) {\n                    if ((x & y) === 0) {\n                        dp[x | y] = Math.min(dp[x | y], dp[x] + dp[y]);\n                    }\n                }\n            }\n        }\n        cur += requiredSubsetSize;\n    }\n\n    return dp[(1 << N) - 1] === Number.MAX_SAFE_INTEGER ? -1 : dp[(1 << N) - 1];\n};\n\n```
['JavaScript']