Easy Solution in O[N*K]
Intuitionfirst i use recursion but it give TLE then i came up this ApprochApproachfind the contribution of each element for  size k(1....k) then multiply it wit
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
 first i use recursion but it give TLE then i came up this Approch

# Approach
<!-- Describe your approach to solving the problem. -->
find the contribution of each element for  size k(1....k) then multiply it with nums[i]

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N*K)

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

# Code
```java []
class Solution {
    public int minMaxSums(int[] nums, int k) {
        
 Arrays.sort(nums); // Sort the array
        long sum = 0; // Use long to avoid overflow
        long MOD = 1_000_000_007;

        long[] fact = new long[nums.length + 1];
        long[] invFact = new long[nums.length + 1];
        precomputeFactorials(fact, invFact, nums.length, MOD); // Precompute factorials

        for (int i = 0; i < nums.length; i++) {
            for (int kSize = 1; kSize <= k; kSize++) {
                // Min contribution
                long minCont = nums[i] * ncr(nums.length - i - 1, kSize - 1, fact, invFact, MOD) % MOD;

                // Max contribution
                long maxCont = nums[i] * ncr(i, kSize - 1, fact, invFact, MOD) % MOD;

                // Add both contributions to the sum
                sum = (sum + minCont + maxCont) % MOD;
            }
        }

        return (int) sum;
    }

    private void precomputeFactorials(long[] fact, long[] invFact, int n, long MOD) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = fact[i - 1] * i % MOD;
        }
        invFact[n] = modInverse(fact[n], MOD);
        for (int i = n - 1; i >= 0; i--) {
            invFact[i] = invFact[i + 1] * (i + 1) % MOD;
        }
    }

    private long ncr(int n, int r, long[] fact, long[] invFact, long MOD) {
        if (n < r || r < 0) return 0; // Invalid cases
        return fact[n] * invFact[r] % MOD * invFact[n - r] % MOD;
    }

    private long modInverse(long x, long MOD) {
        return power(x, MOD - 2, MOD);
    }

    private long power(long base, long exp, long MOD) {
        long result = 1;
        while (exp > 0) {
            if (exp % 2 == 1) {
                result = result * base % MOD;
            }
            base = base * base % MOD;
            exp /= 2;
        }
        return result;
    }
}
```
['Java']