EASY JAVA SOLUTION O(NK) WITH COMBINATORICS
Approach
We can find the maximums and minimums seperately and similarly.
For each element y in nums we say y is the maximum possible value in a subsequence.
Let

# Approach
- We can find the maximums and minimums seperately and similarly.
- For each element y in nums we say y is the maximum possible value in a subsequence.
- Let say we have x count of elements <= y and we have to pick k-1 element at most(This can be done by sorting nums).
- this can be done in this ways: xC0 (not take any) + xC1(take 1 element) + xC2(take 2 elements) .... xCk-1(take k-1 elements).
- we can use inverse modular to divide.

# Complexity
- Time complexity:
O(NlogN + NK + NlogM), M = 10^9(for finding mod inverse)

- Space complexity:
O(N)

# Code
```java []
class Solution {
    public int minMaxSums(int[] nums, int k) {
        long ans = 0;
        int n = nums.length;
        fact = new long[n+1];
        invFact = new long[n+1];
        List<Integer> list = new ArrayList<>();
        for(int x : nums)list.add(x);
        Collections.sort(list);
        for(int i=0;i<n;i++)nums[i] = list.get(i);
        fact[0] = 1;
        invFact[0] = 1;
        for(int i=1;i<=n;i++){
            fact[i] = (fact[i-1] * i) % mod;
            invFact[i] = modExpo(fact[i],mod-2);
        }

        
        for(int i=0;i<n;i++){
            int sC = i;
            int lC= n - i -1;
            for(int j = 0;j<=Math.min(k-1,Math.max(sC,lC));j++) {
                if(j<=sC){
                    ans += (ncr(sC,j) * nums[i]) % mod;
                    ans %=mod;
                }
                if(j<=lC){
                    ans += (ncr(lC,j) * nums[i])%mod;
                    ans %=mod;
                }
                
            }
        }
        return (int)ans;


    }
    long[] fact;
    long[] invFact;
    int mod = (int)1e9 + 7;
    Map<Long,Long> map = new HashMap<>();
    private long ncr(int n,int r){
        if(r>n)return 0;
        return (fact[n] * invFact[r]) % mod * invFact[n-r] % mod;
    }
    private long modExpo(long x, long n){
        if(x == 1)return 1;
        long ans = 1;
        while(n>0){
            if((n&1)==1){
                ans *=x;
                ans%=mod;
                n--;
            }else {
                x*=x;
                n>>=1;
                x%=mod;
            }
        }
        return ans;
    }

}
```
['Java']