Java || easy code 
Complexity
Time complexity:
O(nlogn + nk + n)
Space complexity:
Code


# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(nlogn + nk + n)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ --> O(nK)


# Code
```java []
class Solution {
  
     static long[][] nCr ;
     static int m = 1000000007;
    static void precomputeNCr(int n , int k) {
        nCr = new long[n+1][k+1];
        for (int i = 0; i <=n; i++) {
            nCr[i][0] = 1; // nC0 = 1
            for (int j = 1; j <= Math.min(i, k); j++) {
                nCr[i][j] = (nCr[i - 1][j - 1] + nCr[i - 1][j]) % m;
            }
        }

        for( int i =1 ; i<=n; i++){
            for( int j = 1; j<= Math.min(i,k); j++){
                nCr[i][j] = (nCr[i][j]+ nCr[i][j-1])%m;
            }
        }
    }

    public int minMaxSums(int[] nums, int k) {

        int n = nums.length;
        precomputeNCr(n, k); 
        Arrays.sort(nums);
        long sum = 0;
        for( int i =0; i<n; i++){
            int len = i;
            int len2 = n-i-1;
                if(len> k-1){
                    sum=(sum+ nums[i]* nCr[len][k-1] %m)%m;
                    if(len2>= k-1){
                    sum=(sum+ nums[i]* nCr[len2][k-1] %m)%m;
                        }else {
                                sum= (sum+ nums[i] * nCr[len2][len2]%m)%m;
                        }
                }else {
                    sum= (sum+ nums[i] * nCr[len][len]%m)%m;
                    if(len2>= k-1){
                    sum=(sum+ nums[i]* nCr[len2][k-1] %m)%m;
                        }else {
                                sum= (sum+ nums[i] * nCr[len2][len2]%m)%m;
                        }
                }
        }

        return (int ) (sum)%m;
    }
}
```
['Java']