Python || Cobinations
IntuitionApproachComplexity
Time complexity:
o(N * k)
Space complexity:
o(N)Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# 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(N)

# Code
```python3 []
class Solution:
    def minMaxSums(self, nums, k):
        nums.sort()
        md = 10**9 + 7
        ln = len(nums)
        
        fact = [1] * (ln + 1)
        for i in range(1, ln + 1):
            fact[i] = (fact[i - 1] * i) % md
        
        def mod_inverse(a, p):
            return pow(a, p - 2, p)
        
        inv_fact = [1] * (ln + 1)
        inv_fact[ln] = mod_inverse(fact[ln], md)
        for i in range(ln - 1, 0, -1):
            inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % md
        
        def helper(n, r):
            if r > n or r < 0:
                return 0
            return (fact[n] * inv_fact[r] % md) * inv_fact[n - r] % md
        
        ans = 0
        for i, j in enumerate(nums):
            left, right = i, ln - i - 1
            for x in range(k):
                l = helper(left, x)
                r = helper(right, x)
                ans = (ans + (j * (l + r)) % md) % md
        
        return ans

```
['Array', 'Math', 'Sorting', 'Combinatorics', 'Python3']