Minimum-sum-of-mountain-triplets-I(In Java)
Example:Input: nums = [5, 4, 8, 7, 10, 2]Iteration 1: i = 2 (nums[2] = 8)
Left: l = 4 (nums[1])
Right: r = 7 (nums[3])
Sum: 4 + 8 + 7 = 19.Iteration 2: i = 3 (n
# Example:
Input: nums = [5, 4, 8, 7, 10, 2]

Iteration 1: i = 2 (nums[2] = 8)
Left: l = 4 (nums[1])
Right: r = 7 (nums[3])
Sum: 4 + 8 + 7 = 19.

Iteration 2: i = 3 (nums[3] = 7)
Left: l = 4 (nums[1])
Right: r = 2 (nums[5])
Sum: 4 + 7 + 2 = 13.

Iteration 3: i = 4 (nums[4] = 10)
Left: l = 7 (nums[3])
Right: No valid r.
Skip this iteration.
**Output: 13.**
# Code
```java []
class Solution {
    public int minimumSum(int[] nums) {
        int res = Integer.MAX_VALUE;
        int n = nums.length;
        for(int i=1;i<n-1;i++){
            int l=Integer.MAX_VALUE;
            int r=Integer.MAX_VALUE;
            // Find the smallest element to the left of nums[i] 
            for(int j=0;j<i;j++){
                if(nums[j]<nums[i]){
                    l = Math.min(l,nums[j]);
                }
            }
            // Find the smallest element to the right of nums[i] 
            for(int k=i+1;k<n;k++){
                if(nums[k]<nums[i]){
                    r = Math.min(r,nums[k]);
                }
            }
            // If both l and r are valid, cal the sum of the triplet
            if(l != Integer.MAX_VALUE && r != Integer.MAX_VALUE){
                int sum = l + r + nums[i];
                res = Math.min(sum,res);
            }

        }
        return res == Integer.MAX_VALUE ? -1 : res;
    }
}
```
['Java']