Simple brute force
IntuitionChecking the number of subsequence start or end with the given index or number.Approachto find the number of subsequence of different lenght starting f
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Checking the number of subsequence start or end with the given index or number.
# Approach
<!-- Describe your approach to solving the problem. -->
to find the number of subsequence of different lenght starting from len = 1 to len = k, we find the number using ncr formula and ncr is already precomputed to reduce the time complexity.
# 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(1) if ncr is not taken into account
# Code
```cpp []
class Solution {
public:
        int mod = 1e9 + 7;

    int minMaxSums(vector<int>& nums, int k) {
        sort(nums.begin(),nums.end());
         vector<vector<int>> ncr(nums.size() + 1, vector<int> (k + 1,0));
        ncr[0][0] = 1;
        for (long long n = 1; n <= nums.size(); n++) {
            ncr[n][0] = 1;
            for (long long r = 1; r <= k; r++) 
                ncr[n][r] = (ncr[n - 1][r - 1] + ncr[n - 1][r]) % mod;
        }
        int n = nums.size();
        long long ans = 0;
       for(int i=0;i<n;i++){
           long long temp = 0;
           for(int j=1;j<=k;j++){
               if(j>1){
                   temp += ncr[n-i-1][j-1];
                   temp%=mod;
                   // cout<<temp<<' ' ;
               }
               if(j == 1) temp += 2;
               if(n-i-1 < j -1 )break;
           }
           ans += (temp * nums[i]);
           ans %= mod;
       }
       for(int i=n-1;i>=0;i--){
           long long temp = 0;
           for(int j=1;j<=k;j++){
               if(j>1 && i+1>=j){
                   temp += ncr[i][j-1];
                   temp %= mod;
               }
              
           }
           ans %= mod;
           ans += (temp * nums[i]);
           ans %= mod;
       }
        return ans;
    }
};
```
['Sorting', 'C++']