Java Simple and easy to understand solution,  clean code with comments
PLEASE UPVOTE IF YOU LIKE THIS SOLUTION\n\n### Approach 1\n\nTime Complexity : O (N ^ 2)\nSpace Complexity : O(N)\n\nNote : 41 / 41 test cases passed, but took 
**PLEASE UPVOTE IF YOU LIKE THIS SOLUTION**\n\n### Approach 1\n\nTime Complexity : O (N ^ 2)\nSpace Complexity : O(N)\n\nNote : 41 / 41 test cases passed, but took too long.\n\n```\nclass Solution {\n    \n    static int MOD = (int)(1e9 + 7);\n    public int maxSumMinProduct(int[] nums) {\n\n        \n        int n = nums.length;\n        int[][] arr = new int[n][2];\n        \n        for(int i = 0; i < n; i++){\n            arr[i] = new int[]{i, nums[i]};\n        }\n        \n        Arrays.sort(arr, (a, b) ->  b[1] - a[1]);\n        \n        boolean[] processed = new boolean[n];\n        long maxSum = 0;\n        for(int[] num :  arr){\n            \n            if(processed[num[0]]) continue;\n            \n            long minProduct = getMinProduct(nums, num[0], processed);\n            \n            maxSum = Math.max(maxSum, minProduct);\n        }\n        \n        return (int) (maxSum % MOD);\n    }\n    \n    private long getMinProduct(int[] nums, int index, boolean[] processed){\n        \n        long sum = (long)nums[index];\n        processed[index] = true;\n        \n        //sum %= MOD;\n        \n        int i = index - 1;\n        while(i >= 0 && nums[i] >= nums[index]){\n            sum +=  (long)nums[i];\n            //sum %= MOD;\n            \n            processed[i] = true;\n            \n            i--;\n        }\n        \n        \n         i = index + 1;\n        while(i < nums.length && nums[i] >= nums[index]){\n            sum += (long)nums[i];\n            //sum %= MOD;\n            processed[i] = true;\n            i++;\n        }\n        \n        \n        long product = sum * (long)nums[index];\n        \n        return product;\n    }\n}\n```\n\n\n\n\n\n\n\n\n### Approach 2\n\nTime Complexity : O (N)\nSpace Complexity : O(N)\n\n```\nclass Solution {\n    static int MOD = (int)(1e9 + 7);\n    public int maxSumMinProduct(int[] nums) {\n        int n = nums.length;\n        //leftMin[i] = give the index(left direction) which value is less than nums[i] \n        int[] leftMin  = getLeftMinIndex(nums);\n        \n        //rightMin[i] = give the index(right direction) which value is less than nums[i]\n        int[] rightMin = getRightMinIndex(nums);\n        \n        long[] prefixSum = getPrefixSum(nums);\n        \n\n        long maxProduct = 0l;\n        \n        for(int i = 0; i < n; i++){\n            long sum = leftMin[i] == -1 ? prefixSum[rightMin[i] - 1] :  prefixSum[rightMin[i] - 1] -  prefixSum[leftMin[i]];\n            long product = sum * nums[i];\n            \n            //update max product\n            maxProduct = Math.max(product, maxProduct);\n        }\n        \n        return (int) (maxProduct % MOD);\n    }\n    \n    private int[] getLeftMinIndex(int[] nums){\n        int n = nums.length;\n        \n        int[] arr = new int[n];\n        Arrays.fill(arr, -1);\n        \n        Stack<Integer> stack = new Stack();\n        \n        for(int i = 0; i < n; i++){\n            \n            //remove all the index which value is greater or equal to current number\n            while(!stack.isEmpty() && nums[i] <= nums[stack.peek()]){\n                stack.pop();\n            }\n            \n\n            //check is any index which is less than current number\n            if(!stack.isEmpty() && nums[i] > nums[stack.peek()]){\n                arr[i] = stack.peek();\n            }\n            \n            stack.push(i);\n        }\n        \n        \n        return arr;\n    }\n    \n    private int[] getRightMinIndex(int[] nums){\n        int n = nums.length;\n        \n        int[] arr = new int[n];\n        Arrays.fill(arr, n);\n        \n        Stack<Integer> stack = new Stack();\n        \n        for(int i = n - 1; i >= 0; i--){\n            \n            //remove all the index which value is greater or equal to current number\n            while(!stack.isEmpty() && nums[i] <= nums[stack.peek()]){\n                stack.pop();\n            }\n            \n            //check is any index which is less than current number\n            if(!stack.isEmpty() && nums[i] > nums[stack.peek()]){\n                arr[i] = stack.peek();\n            }\n            \n            stack.push(i);\n        }\n        \n        \n        return arr;\n    }\n    \n    private long[] getPrefixSum(int[] nums){\n        int n = nums.length;\n        \n        long[] arr = new long[n];\n        arr[0] = nums[0];\n        \n        for(int i = 1; i < n; i++){\n            arr[i] = nums[i] + arr[i - 1];\n        }\n        \n        return  arr;\n    }\n}\n```
['Java']