JAVA Simple Solution using stacks || Application of next smaller element
Explanation:\n \neg: nums= [2,3,3,1,2]\n\n step1: psum =[2,5,8,9,11]\n step2 :Numbers are always positive. So no need to check small subarray check the largest 
**Explanation:**\n ```\neg: nums= [2,3,3,1,2]\n\n step1: psum =[2,5,8,9,11]\n step2 :Numbers are always positive. So no need to check small subarray check the largest possible subarray for every element where it is minimum. (similar idea as of max area of histogram)\n  \n      leftmin=[-1,0,0,-1,3];\n      rightmin=[3,3,3,5,5];\n      \n      -> every element is minimum in subarray (left[i]+1 to right[i]-1) So calculate sum from from (left to right)*nums[i]\n        \n        max=Math.max(max,(prefix[right-1]-prefix[left])*nums[i]);\n        if(left==-1) we have to handle that to.\n```\n**CODE:**\n```\nclass Solution {\n    public int maxSumMinProduct(int[] nums) {\n        int mod=(int)Math.pow(10,9)+7;\n        int n=nums.length;\n        \n        //next smaller on left\n        int[] left=new int[n];\n        Stack<Integer> st=new Stack<>();\n        left[0]=-1;\n        st.push(0);\n        for(int i=1;i<n;i++){\n            while(st.size()>0 && nums[st.peek()]>=nums[i]){\n                st.pop();\n            }\n            \n            if(st.size()==0) left[i]=-1;\n            else left[i]=st.peek();\n            \n            st.push(i);\n        }\n        \n        //next smaller on right\n        int[] right=new int[n];\n        st=new Stack<>();\n        right[n-1]=n;\n        st.push(n-1);\n        for(int i=n-2;i>=0;i--){\n        while(st.size()>0 && nums[st.peek()]>=nums[i]) st.pop();\n            \n            if(st.size()>0) right[i]=st.peek();\n            else right[i]=n;\n            \n            st.push(i);\n        }\n        \n        long[] prefixSum=new long[n];\n        prefixSum[0]=nums[0];\n        for(int i=1;i<n;i++) prefixSum[i]=prefixSum[i-1]+nums[i];\n        \n      \n        long max=0;\n        for(int i=0;i<nums.length;i++){\n            int l=left[i];\n            int r=right[i]-1;\n            \n            max=Math.max(max,(prefixSum[r]-(l==-1?0:prefixSum[l]))*nums[i]);\n        }\n        return (int)(max%mod);\n    }\n}\n```\n\n**Complexity:**\n`Time:O(n) and Space:O(n)`\n\n**Similar Questions:**\n[largest rectangle in histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/)\n[maximal rectangle](https://leetcode.com/problems/maximal-rectangle/)\n\nPlease upvote if found it helpful :)
['Stack', 'Java']