✅🔥 || Easy to Understand Solution || DP || Tabulation || Pascal Triangle
IntuitionFormation of numbers like pascal's triangle then multiplying the number and then adding the number*numbers[maxy]ApproachIf you check the numbers are re
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Formation of numbers like pascal's triangle then multiplying the number and then adding the number*numbers[maxy]
# Approach
<!-- Describe your approach to solving the problem. -->
If you check the numbers are repeating in pascal triangle format 

`1` 0 0 0
`1 1 `0 0
`1 2 1` 0
`1 3 3 1` 
.....



we choose the width of pascal triangle as k and height as n

we took sumy=0

for max number we add all the number
- pascal triangle means for 1 2 1 nums[2] (3rd row) after sorting will repeat 1 + 2+1 times

for min number we add all the numbers but in the flip the dp 
- for nums.size()=3 for nums[0] it will repeat for pascal(n-row) that is pascal(3-1) that is pascal of `1 2 1` 







# Code
```cpp []
class Solution {
public:
    int minMaxSums(vector<int>& nums, int k) {
         int MOD = 1e9 + 7;
        int n = nums.size();

        sort(nums.begin(), nums.end());

        vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, 0));
        dp[0][0] = 1; 

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= k; j++) {
                dp[i][j] = dp[i - 1][j] % MOD;

                if (j > 0) {
                    dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
                }
            }
        }

        long long sumy = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= k; j++) {
                sumy = (sumy + nums[i - 1] * dp[i - 1][j - 1] % MOD) % MOD;
            }
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= k; j++) {
                sumy = (sumy + nums[i - 1] * dp[n - i][j - 1] % MOD) % MOD;
            }
        }

        return sumy % MOD;
    }
};

```
['Dynamic Programming', 'Brainteaser', 'C++']