tabulation java code
IntuitionApproachComplexity
Time complexity:

Space complexity:
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)$$ -->

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

# Code
```java []
class Solution {
    public int minMaxSums(int[] nums, int k) {
        Arrays.sort(nums);
        int mod = 1000000007;
     long[][] ncr = new long[k+1][nums.length+1];
     for(int i = 0;i<ncr.length;i++){
        for(int j =0;j<ncr[0].length;j++){
            if(i == 0){
                ncr[i][j] = 1;
            }else if(j == 0){
                ncr[i][j] = 0;
            }else{
                ncr[i][j] = (ncr[i-1][j-1] + ncr[i][j-1])%mod;
            }
        }
     }   
     long[][] dp1 = new long[k+ 1][nums.length + 1];
     for(int i = 1;i<dp1.length;i++){
        for(int j = 1;j<dp1[0].length;j++){
            if(i == 1){
                dp1[i][j] = (dp1[i][j-1] + nums[j-1])%mod;
            }else{
                dp1[i][j] = (dp1[i-1][j-1]  + dp1[i][j-1])%mod;
            }
        }
     }
     long[][] dp2 = new long[k+1][nums.length+1];
     for(int i = 1;i<dp2.length;i++){
        for(int j =1;j<dp2[0].length;j++){
            if(i == 1){
             dp2[i][j] = (dp2[i][j-1] + nums[j-1])%mod;   
            }else{
                dp2[i][j] = ((ncr[i-1][j-1]*nums[j-1])%mod + dp2[i][j-1])%mod;
            }
        }
     }
     long ans = 0;
     for(int i = 0;i<dp1.length;i++){
        ans = (ans + (dp1[i][nums.length] + dp2[i][nums.length])%mod)%mod;
     }
     return (int)ans;
    }
}
```
['Java']