"Mountain Climbing on a Budget" 🚀⛰️💰
Intuition
The problem requires finding a mountain triplet (i, j, k) where
nums[i] < nums[j] > nums[k] and returning its minimum sum. We use a brute-force approa
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- The problem requires finding a mountain triplet (i, j, k) where   
`nums[i] < nums[j] > nums[k]` and returning its minimum sum. We use a brute-force approach by checking all possible triplets and keeping track of the smallest valid sum. If no such triplet exists, we return `-1`.
---
# Approach
<!-- Describe your approach to solving the problem. -->
1. **Initialize Variables** – Use `min_sum` to store the minimum valid mountain sum, `sum` for the current triplet sum, and `found` to check if a valid triplet exists.

2. **Iterate Through Triplets** – Use three nested loops to generate all possible triplets `(i, j, k)`, ensuring `i < j < k`.

3. **Check Mountain Condition** – Ensure `nums[i] < nums[j]` and 
`nums[k] < nums[j]` to validate the mountain shape.

4. **Update Minimum Sum** – If a valid triplet is found, calculate its sum and update `min_sum` accordingly.

5. **Return Result** – If at least one valid triplet is found, return `min_sum`; otherwise, return `-1`.

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

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

---
# Code
```java []
class Solution {
    public int minimumSum(int[] nums) {
    int min_sum=Integer.MAX_VALUE, sum=-1;
    boolean found=false;

        for(int i=0; i<nums.length; i++)
        {
            for(int j=i+1; j<nums.length; j++)
            {
                for(int k=j+1; k<nums.length; k++)
                {
                    if(nums[i]<nums[j] && nums[k]<nums[j])
                    {
                        sum=nums[i]+nums[j]+nums[k];
                        min_sum=Math.min(min_sum,sum);
                        found=true;
                    }
                }
            }    
        }

        return found ? (min_sum) : -1;
    }
}
```
```C++ []
class Solution {
public:
    int minimumSum(vector<int>& nums) {
    int min_sum=INT_MAX, sum=-1;
    bool found=false;

        for(int i=0; i<nums.size(); i++)
        {
            for(int j=i+1; j<nums.size(); j++)
            {
                for(int k=j+1; k<nums.size(); k++)
                {
                    if(nums[i]<nums[j] && nums[k]<nums[j])
                    {
                        sum=nums[i]+nums[j]+nums[k];
                        min_sum=min(min_sum,sum);
                        found=true;
                    }
                }
            }    
        }

        return found ? (min_sum) : -1;
    }
};
```
```C []
int minimumSum(int* nums, int numsSize) {
    
    int min_sum=INT_MAX, sum=-1;
    bool found=false;

        for(int i=0; i<numsSize; i++)
        {
            for(int j=i+1; j<numsSize; j++)
            {
                for(int k=j+1; k<numsSize; k++)
                {
                    if(nums[i]<nums[j] && nums[k]<nums[j])
                    {
                        sum=nums[i]+nums[j]+nums[k];
                        min_sum=fmin(min_sum,sum);
                        found=true;
                    }
                }
            }    
        }

        return found ? (min_sum) : -1;
}
```
---
![sution section image.jpeg](https://assets.leetcode.com/users/images/5cfa6eec-d701-4468-b873-038698bb8faf_1738487890.9654057.jpeg)

['Array', 'C', 'C++', 'Java']