C++ Brute Force || PreCompute
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach1:\n\n\nclass Solution {\npublic:\n    int minimumSum(vector<int>& nums) {\n
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach1:**\n\n```\nclass Solution {\npublic:\n    int minimumSum(vector<int>& nums) {\n        int n=nums.size();\n        int ans=INT_MAX;\n        for(int i=0;i<n-2;i++){\n            for(int j=i+1;j<n-1;j++){\n                for(int k=j+1;k<n;k++){\n                    if(nums[i] < nums[j] && nums[k] < nums[j]) ans = min(ans,nums[i]+nums[j]+nums[k]);\n                }\n            }\n        }\n        \n        return (ans==INT_MAX ? -1:ans);\n    }\n};\n```\n\n**Approach2:**\n* consider each index "i" as peak of mountain triplet\n* precompute minimum value for left [0,i-1] and right [i+1,n-1]\n\n```\nclass Solution {\npublic:\n    int minimumSum(vector<int>& nums) {\n        int n=nums.size();\n        \n        vector<int> left_min(n);\n        left_min[0]=nums[0];\n        for(int i=1;i<n;i++) left_min[i]=min(left_min[i-1],nums[i]);\n        \n        vector<int> right_min(n);\n        right_min[n-1]=nums[n-1];\n        for(int i=n-2;i>=0;i--) right_min[i]=min(right_min[i+1],nums[i]);\n            \n        \n        int ans=INT_MAX;\n        \n        for(int i=1;i<n-1;i++){\n            if(nums[i]>left_min[i-1] && nums[i]>right_min[i+1]) ans=min(ans,left_min[i-1]+nums[i]+right_min[i+1]);\n        }\n        \n        return (ans==INT_MAX ? -1:ans);\n    }\n};\n```
[]