O(n) time complexity solution
Bold# Intuition\n Describe your first thoughts on how to solve this problem. \nTo get the minimum sum , the very first thought which should strike is to find th
**Bold**# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo get the minimum sum , the very first thought which should strike is to find the two minimum points(min elements) that can form a mountain with any of the elements in between them.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Make left array which stores min element from the left side of that element including itself.\n2. Make right array which stores min element from the right side of that element including itself.\n3. find all triplets that form a mountain and store a min sum.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(n)\n\n# Code\n```\nclass Solution {\n    public int minimumSum(int[] nums) {\n      int ans=Integer.MAX_VALUE;\n      int n=nums.length;\n      int left[]=new int[n];\n      int right[]=new int[n];\n      left[0]=nums[0];\n    //   left array stores min ele from left side including itself\n      for(int i=1;i<n;i++)\n          left[i]=Math.min(left[i-1],nums[i]);\n      \n      right[n-1]=nums[n-1];\n    //   right array stores min from right side;\n      for(int i=n-2;i>=0;i--)\n          right[i]=Math.min(right[i+1],nums[i]);\n\n      for(int i=1;i<n-1;i++)\n      {\n          if(left[i-1]<nums[i] && right[i+1]<nums[i])\n          ans=Math.min(ans,left[i-1]+nums[i]+right[i+1]);\n      } \n      return ans==Integer.MAX_VALUE?-1:ans;  \n    } \n}\n```
['Java']