Pure combinatorics and factorial precomputations
IntuitionLet's sort the initial array. At each index we will know the number of elements we can pick the subsequence to guarantee that current element is min or
# Intuition
Let's sort the initial array. At each index we will know the number of elements we can pick the subsequence to **guarantee** that current element is min or max in it.

# Approach
Number of ways to pick `r` items out of `n` where order does not matter (we always pick in order due to "subsequence" requirement) is just `nCr(n, r)` - binomial coeff.
Iterating for `[1, min(n, k)]` where `n` is the number of elements smaller / larger than current and sum counts together gives us number of ways to pick at most `k` items out of `n`.
And don't forget to keep modulo division going.

# Complexity
- Time complexity:
$$O(10^5 * log(mod))$$ to precompute factorials
$$O(n*log(n))$$ for the actual algo

- Space complexity:
$$O(10^5)$$

# Code
```java []
class Solution {
    static final long mod = 1_000_000_007L;
    static long[] fact;
    static long[] invFact;

    static void fill() {
        fact[0] = 1;
        for (int i = 1; i < fact.length; i++) {
            fact[i] = (fact[i - 1] * i) % mod;
        }

        invFact[fact.length - 1] = modPow(fact[fact.length - 1], mod - 2, mod);
        for (int i = fact.length - 2; i >= 0; i--) {
            invFact[i] = (invFact[i + 1] * (i + 1)) % mod;
        }
    }

    static long modPow(long base, long exp, long mod) {
        long result = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) {
                result = (result * base) % mod;
            }
            base = (base * base) % mod;
            exp >>= 1;
        }
        return result;
    }

    static long nCr(int n, int r) {
        return fact[n] * invFact[r] % mod * invFact[n - r] % mod;
    }

    static long count(int n, int k) {
        long res = 0L;
        for (int i = 1; i <= Math.min(k, n); i++) {
            res = (res + nCr(n, i)) % mod;
        }
        return res;
    }
    
    public int minMaxSums(int[] nums, int k) {
        if (fact == null) {
            fact = new long[100_001];
            invFact = new long[100_001];
            fill();
        }
        Arrays.sort(nums);
        long res = 0L;
        for (int i = 0; i < nums.length; i++) {
            int len = nums.length - i - 1;
            long count = count(len, k - 1) + 1L;
            res = (res + (nums[i] * count) % mod) % mod;
            res = (res + (nums[len] * count) % mod) % mod;
        }
        return (int) res;
    }
}
```
['Math', 'Combinatorics', 'Java']