previous & next smaller element and prefix sum will together will solve this..
\n    def maxSumMinProduct(self, nums: List[int]) -> int:\n        """\n        How can we solve this problem?\n        \n        is sorting comes into the pict
\n    def maxSumMinProduct(self, nums: List[int]) -> int:\n        """\n        How can we solve this problem?\n        \n        is sorting comes into the picture ?\n        Nope right otherwise order will be ignored\n        \n        It is not like that we need to take min element of an array\n        so basically for each subarray we will get sum and its minimum element\n        then its product is its weight and we need the max weight subarray\n        \n        can we come from back?\n        without generating subarray can we do that?\n        si there any observation which we can make?\n        \n        we need non empty subarray weight\n        \n        is there any prefix and suffix sum logic\n        [1,2,3,2]\n        [1,3,6,8]\n        [8,7,5,2]\n        \n        stack => not getting how stack comes into the picture\n        Monotonic stack => \n        not getting anything\n        queue => not getting anything\n        Heap => Nope\n        tree, graph => do we need to convert this array to tree or graph\n        still we need to poll n ^ 2 subarrays\n        \n        what things will help us in subarray problem?\n        sliding window\n        bit manipulation\n        \n        if we sort by val and attached by indices\n        [(1,0),(2,1),(2,3),(3,2)]\n        \n        first ele can be min for whole array\n        second can be min for array range from \n        \n        is this prev smaller and next smaller ele problem\n        and to we need prefix sum array to get sum of subarray\n        based on prev smaller and next smaller ele index\n        \n        tc = O(n + n + n + n) => O(4n) => O(n)\n        sc = O(n + n + n) => O(3n) => O(n)\n        """\n        def prevSmallerElement(nums):\n            n = len(nums)\n            stack = []\n            pse = [-1] * n\n            for idx in range(n - 1,-1,-1):\n                while stack and nums[stack[-1]] > nums[idx]:\n                    top = stack.pop()\n                    pse[top] = idx\n                stack.append(idx)\n            return pse\n        \n        def nextSmallerElement(nums):\n            stack = []\n            n = len(nums)\n            nse = [n] * n\n            for idx in range(n):\n                while stack and nums[stack[-1]] > nums[idx]:\n                    top = stack.pop()\n                    nse[top] = idx\n                stack.append(idx)\n            return nse\n        \n        def preparePrefixArr(nums):\n            n = len(nums)\n            prefixArr = [0] * n\n            prefixArr[0] = nums[0]\n            for idx in range(1,n):\n                prefixArr[idx] = prefixArr[idx - 1] + nums[idx]\n            return prefixArr\n                \n        \n        pse = prevSmallerElement(nums)\n        nse = nextSmallerElement(nums)\n        prefixArr = preparePrefixArr(nums)\n        maxSumMinProduct = -math.inf\n        mod = (10 ** 9) + 7\n        for idx in range(len(nums)):\n            currentMinElement = nums[idx]\n            leftBoundary = pse[idx]\n            rightBoundary = nse[idx]\n            subarraySumWhereCurrentEleIsMin = prefixArr[rightBoundary - 1] - (0 if leftBoundary == -1 else prefixArr[leftBoundary])\n            currentSubarrayWeight = currentMinElement * subarraySumWhereCurrentEleIsMin\n            maxSumMinProduct = max(maxSumMinProduct, currentSubarrayWeight)\n        \n        return maxSumMinProduct % mod\n    def bruteForce(self,nums):\n        """\n        brute force is for every subarray \n        keep track of sum and minimum and then keep track of maximum\n        among them\n        """\n        windowSum = 0\n        minInWindow = math.inf\n        maxSumMinProd = -math.inf\n        n = len(nums)\n        for i in range(n):\n            windowSum = 0\n            minInWindow = math.inf\n            for j in range(i,n):\n                minInWindow = min(minInWindow, nums[j])\n                windowSum += nums[j]\n                currSumMinProd = minInWindow * windowSum\n                maxSumMinProd = max(maxSumMinProd, currSumMinProd)\n        return maxSumMinProd
['Stack', 'Prefix Sum']