Optimize Solution Of Minimum Sum Of Mountain Triplets-i....
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int minimumSum(vector<int>& nums) {
        int n=nums.size();
        vector<int> left(n,INT_MAX);
        vector<int> right(n,INT_MAX);
        int minleft=nums[0],minright=nums[n-1];
       for(int i=1;i<n;i++){
        left[i]=minleft;
        minleft=min(minleft,nums[i]);
       } 
       for(int i=n-2;i>=0;i--){
        right[i]=minright;
        minright=min(minright,nums[i]);
       }
       int ans=INT_MAX;
       for(int i=1;i<n-1;i++){
        if(left[i]<nums[i] &&right[i]<nums[i]){
            ans=min(ans,left[i]+right[i]+nums[i]);
        }
       }
       return (ans==INT_MAX)?-1:ans;
    }
};
```
['C++']