Very well, explain
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
```java []
/*
class Solution {
    public int minimumSum(int[] nums) {
        // bich wala bara hona chaiye i <j<k index ka order maintain krke he 
        // yani j sbse bara or i and k chota j se or to aur miljaye aisa to minmm sum bhi hona chiye
        
        int n = nums.length;
        int minSum = Integer.MAX_VALUE;
        boolean found = false;

        // 3 loop lga liye 
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                for (int k = j + 1; k < n; k++) {
                    // whi condition check kr rhe ki miljaye 

                    if (nums[i] < nums[j] && nums[k] < nums[j]) {
                        int sum = nums[i] + nums[j] + nums[k];
                        // ab sum ko check kro minm ha ya nhi baki or agr aisa triplet milta ha usse 
                        if (sum < minSum) {
                            minSum = sum;
                            found = true;
                        }
                    }
                }
            }
        }
        // agr mila ha to minsum return krdo nhi mila to -1 return krdo
        return found ? minSum : -1;
    }
}
*/

class Solution {
    public int minimumSum(int[] nums) {
        // krna kya ha har j ke liye dono side uska minm value dekhna hai yani 
        // leftmin and rightmin or each j 
        // 0th ka left nhi hota last ka right nhi hota to dono ko chor do 
        int[] leftMin = new int[nums.length];
        int[] rightMin = new int[nums.length];
        
        //ek var le rhe track krne ko prev min ky tha 
        int prevLeft = Integer.MAX_VALUE;
        int prevRight = Integer.MAX_VALUE;
        
        // dono kaam ek he loop se kar rhe mja aaega dekho
        for (int i = 0, j = nums.length - 1; i < nums.length; i++, j--) {
            // Store the minimum value on the left side of the current element
            leftMin[i] = Math.min(nums[i], prevLeft);
            // Store the minimum value on the right side of the current element
            rightMin[j] = Math.min(nums[j], prevRight);
            // Update the previous left and right minimum values
            prevLeft = leftMin[i];
            prevRight = rightMin[j];
        }
        // nums = [8,6,1,5,3]
        //leftMin=[8,6,1,1,1]
        // rigMin=[1,1,1,3,3]
        
        // Variable to store the minimum sum
        int minSum = Integer.MAX_VALUE;
        
        // Iterate over the elements to find valid mountain triplets and calculate the minimum sum
        for (int i = 1; i < nums.length - 1; i++) {
            // Check if the current element is a peak
            if (nums[i] > leftMin[i - 1] && nums[i] > rightMin[i + 1]) {
                // Calculate the sum of the mountain triplet and update minSum if necessary
                minSum = Math.min(minSum, leftMin[i - 1] + nums[i] + rightMin[i + 1]);
            }
        }
        
        // Return the minimum sum if found, otherwise return -1
        return minSum == Integer.MAX_VALUE ? -1 : minSum;
    }
}

```
['Prefix Sum', 'Java']