JAVA EASY SOLUTION BEATS 100%
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
![IMG_2782_compressed (1)_compressed-compressed_page-0001 (1).jpg](https://assets.leetcode.com/users/images/91826ce4-43a5-43be-86d6-0d0eac39e1f6_1737353756.4717135.jpeg)
<!-- 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) {
        int n = nums.length;
        if (n < 3) return -1;

        int[] leftprefix = new int[n];
        int[] rightprefix = new int[n];

      
        int leftmin = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
             leftmin = Math.min(leftmin, nums[i]);
            leftprefix[i] = leftmin;
           
        }

       
        int rightmin = Integer.MAX_VALUE;
        for (int j = n - 1; j >= 0; j--) {
             rightmin = Math.min(rightmin, nums[j]);
            rightprefix[j] = rightmin;
           
        }

        int ans = Integer.MAX_VALUE;

       
        for (int i = 1; i < n - 1; i++) {
            if (nums[i] > leftprefix[i - 1] && nums[i] > rightprefix[i + 1]) {
                ans = Math.min(ans, leftprefix[i - 1] + nums[i] + rightprefix[i + 1]);
            }
        }

        return ans == Integer.MAX_VALUE ? -1 : ans;
    }
}

```
['Java']