❇ minimum-sum-of-mountain-triplets-i Images👌 🏆O(N)❤️ Javascript🎯 Memory👀95%🕕 ++Explanation✍️🔴�
Time Complexity: O(N)\uD83D\uDD55\nSpace Complexity: O(N)\n\n\nvar minimumSum = function (nums) {\n    const minLeftToRight = [Infinity];\n    const minRightToL
**Time Complexity: O(N)\uD83D\uDD55\nSpace Complexity: O(N)**\n\n```\nvar minimumSum = function (nums) {\n    const minLeftToRight = [Infinity];\n    const minRightToLeft = [Infinity];\n\t\n\t// minLeftToRight\n    for (let index = 0; index < nums.length; index++) {\n        const minNum = minLeftToRight[minLeftToRight.length - 1];\n        if (minNum < nums[index]) {\n            minLeftToRight.push(minNum);\n        } else {\n            minLeftToRight.push(nums[index]);\n        }\n    }\n\t\n\t// minRightToLeft\n    for (let index = nums.length - 1; index >= 0; index--) {\n        const minNum = minRightToLeft[minRightToLeft.length - 1];\n        if (minNum < nums[index]) {\n            minRightToLeft.push(minNum);\n        } else {\n            minRightToLeft.push(nums[index]);\n        }\n    }\n\t\n    minRightToLeft.reverse();\n    let minSum = Infinity;\n    for (let index = 1; index < nums.length - 1; index++) {\n        const element = nums[index];\n        if (nums[index] > minLeftToRight[index] && nums[index] > minRightToLeft[index]) {\n            minSum = Math.min(minSum, nums[index] + minLeftToRight[index] + minRightToLeft[index]);\n        }\n    }\n    return minSum === Infinity ? -1 : minSum;\n};\n```\n![image](https://assets.leetcode.com/users/images/3d74c899-6721-4595-9ef1-0319955909e0_1727500682.8069236.png)\n![image](https://assets.leetcode.com/users/images/e3c9692e-4786-4f4b-9da9-2ee167d07f70_1727500694.5954037.png)\n\nPlease upvote \uD83D\uDCAA if like\n\n
['Heap (Priority Queue)', 'JavaScript']