Javascript - Combinatorics
Code
# Code
```javascript []
/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var minMaxSums = function (nums, k) {
  nums.sort((a, b) => a - b);
  const MOD = 10 ** 9 + 7;
  const len = nums.length;
  const numOfComb = new Array(len + 1)
    .fill()
    .map(() => new Array(k + 1).fill(0));

  numOfComb[0][0] = 1;
  for (let n = 1; n <= len; n++) {
    numOfComb[n][0] = 1;
    for (let r = 1; r <= k; r++) {
      numOfComb[n][r] = (numOfComb[n - 1][r - 1] + numOfComb[n - 1][r]) % MOD;
    }
  }

  let ans = 0n;
  for (let n = 0; n < len; n++) {
    let numOfSubsequences = 0;
    for (let r = 0; r <= k - 1; r++) {
      if (n < r) break;
      numOfSubsequences = (numOfSubsequences + numOfComb[n][r]) % MOD;
    }
    const curr =
      BigInt(nums[n] + nums[len - 1 - n]) * BigInt(numOfSubsequences);
    ans = (ans + curr) % BigInt(MOD);
  }

  return Number(ans);
};

```
['Combinatorics', 'JavaScript']