✅🔥 || Easy to Understand Solution || DP || Recursion || Memoization
IntuitionApproachComplexity
Time complexity:
Time complexity:--> O(nlogn+n⋅k)
Space complexity:
Space Complexity :-->  O(n⋅k)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)$$ -->

Time complexity:--> O(nlogn+n⋅k)



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

# Code
```cpp []
class Solution {
public:
const int MOD=1e9+7;
int mini=INT_MAX;
    int f(int i,vector<int>& nums, int k,vector<vector<int>>&dp){
        if(k==0) return 0;
        if(i>=nums.size()) return 0;
        if(dp[i][k]!=-1) return dp[i][k];

        int take=nums[i]+f(i+1,nums,k-1,dp);
        int skip=f(i+1,nums,k,dp);
        return dp[i][k]=(take%MOD+skip%MOD)%MOD;
    }

    int minMaxSums(vector<int>& nums, int k) {

        sort(nums.begin(),nums.end());
        int ans=0;
        int n=nums.size();
        vector<vector<int>>dp1(n,vector<int>(102,-1));
        int maxi= f(0,nums,k,dp1);
        vector<vector<int>>dp2(n,vector<int>(102,-1));
        reverse(nums.begin(),nums.end());
        int mini= f(0,nums,k,dp2);

        return (maxi+mini)%MOD;
        
    }
};
```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']